3

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.

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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