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 got files named like this:

cam1(word1 word2 wordN) (24-04-2012 00-11-13).mpg
cam2(word1 word2 wordN) (24-04-2012 00-11-13).mpg
cam3(word1 word2 wordN) (24-04-2012 00-11-13).mpg

Need to cut (word1 word2 word3) and replace spaces with _ Renamed files expected:

cam1_(24-04-2012_00-11-13).mpg
cam2_(24-04-2012_00-11-13).mpg
cam3_(24-04-2012_00-11-13).mpg

In the first brackets could be different number of "word". Timestamp is always the same.

share|improve this question
    
is PowerShell ok? In PowerShell you can use regular expressions for renaming. It might be possible in pure batch with a few nested For /F loops, or lots of %FOO:search=replace% in case the number of possible different words is small, but it would be definitely more ugly :) –  mihi Apr 25 '12 at 17:20
add comment

2 Answers

Add this code to a batchfile.

For /f "tokens=1-3 delims=(" %%a in ('dir *.mpg /b') do call :DoRename "%%a" "%%b" "%%c"

Goto :eof
:DoRename
  Set SrcFile=%1(%2(%3
  Set SrcFile=%srcfile:"=%

  Set DestFile=%1 (%3
  Set DestFile=%DestFile:"=%
  Set DestFile=%DestFile: =_%

  Rename "%SrcFile%" "%DestFile%"
share|improve this answer
    
ZEDA-NL, your script does replace space with _ , however I also need to remove (word1 word2 etc). Those words could be different like (description of event 15) or (this is test). I need to remove that part completely from the filename. –  Igor Apr 25 '12 at 19:34
    
I didn't realize that the words were different all the time. I modified the script so it should work now. –  ZEDA-NL Apr 25 '12 at 21:01
add comment

I've used Bulk Rename Utility for just this sort of thing. It allows you remove, edit, replace or add numbers to filenames easily. And it does batch files. I use it all the time for renaming photos and video clips as well as mp3 files.

share|improve this answer
    
I need it to run it automatically from scheduler, –  Igor Apr 25 '12 at 16:34
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.