Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

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:… and… – 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .