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 hundreds of folders named after movies. In each folder there's a .mkv file (or .avi, .mp4), named differently. In each folder there's a folder.jpg.

I'd like to rename each video file so that it carries the name of its parent folder. folder.jpg must stay unchanged though.

For example, the folder structure is like this:

 - Movies/Stirb Langsam 1/stlg1.mkv
 - Movies/Stirb Langsam 2/stlg2.mkv
 - Movies/Star Wars 1/hhgdtebds.mkv
 - Movies/Star Wars 2/stwa2.mkv

And should be:

 - Movies/Stirb Langsam 1/Stirb Langsam 1.mkv
 - Movies/Stirb Langsam 2/Stirb Langsam 2.mkv
 - Movies/Star Wars 1/Star Wars 1.mkv
 - Movies/Star Wars 2/Star Wars 2.mkv

At the moment I use Windows 7 for that. Would be nice if one of the scripting gurus could help me.

share|improve this question

1 Answer 1

Save this as a batch file in the root of your tree:

@echo off
for /r /d %%x in (*) do (
 pushd "%%x"
 echo %%x
 for /F "delims=" %%i in ("%%x") do (
  ren *.mkv "%%~ni.mkv" 2> NUL
  ren *.avi "%%~ni.avi" 2> NUL
  ren *.mp4 "%%~ni.mp4" 2> NUL
 )
 popd
)

Disclaimer: I bear no responsibility for any damage caused.

Though I've tested it on the list you gave, I highly recommend that you back up the files before running the batch file.

share|improve this answer
    
By the way, my script was based on answers to these questions: stackoverflow.com/questions/2043869/… and stackoverflow.com/questions/3432851/… –  Gnubie Oct 5 '12 at 17:15
    
Thank you, the script worked for files without a blank and without dot in the name. I found a tool, that helped me out for the rest. <<advanced renamer>> –  Andreas Oct 9 '12 at 9:19

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.