Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have files with filenames such as this:

かな_かな

I'd like to replace that with just:

かな

Is there any way to do this in batch, automatically?

Note that some files have different words before and after the underscore so I can't just strip the first part of the filename.

(PowerShell, Terminal, or any free 3rd party tool is fine...)

share|improve this question
    
It would be helpful if you said what system you are running. –  Scott Nov 16 '12 at 17:48
    
Windows, but I have access to Linux, if necessary. –  Philip Seyfi Nov 16 '12 at 19:17
add comment

1 Answer 1

Since you mention “batch” and “PowerShell”, I guess you’re running Windows.  I doubt that ordinary Windows batch can handle this, and I don’t know PowerShell.  However, this question is essentially the same question, but for Unix/Linux, and specifically for “bash”.  I’ll give you a “bash” answer for your question, based on the answers to that other question:

ls -d *_* | grep '^\(.*\)_\1$' | while read xx
do
    x=$(echo "$xx" | sed 's/^\(.*\)_\1$/\1/')
    mv "$xx" "$x"
done

Perhaps you can find a version of “bash” that you can download.  Perhaps somebody who knows PowerShell can adapt the above so you can use it.

share|improve this answer
    
Thank you for your answer. I'll give it a try. If someone could adapt this for PowerShell, that would be fantastic! –  Philip Seyfi Nov 16 '12 at 19:19
    
If you “have access to Linux”, you should be able to use the above as-is. –  Scott Nov 16 '12 at 19:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.