Take the 2-minute tour ×

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

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
    x=$(echo "$xx" | sed 's/^\(.*\)_\1$/\1/')
    mv "$xx" "$x"

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


