Renaming files within folders to folder name

August 22, 2011 at 08:57:11
Specs: Windows 7
I'm looking for some help creating a batch file that will rename a file within a folder to the same name as that folder.

ex. main directory: c:\movies
within movies will be a large list of folders, ex: Kick-ass [2010] within that folder will be a file such as 52342342.avi.

I want to rename 52342342.avi to Kick-ass [2010].avi.

I want it to be as automated as possible since its a large list of files and I don't want to have to type in each directory (c:\movies\Kick-ass [2010] ect).

Is that possible or am I reaching for the stars?

See More: Renaming files within folders to folder name

Report •

August 22, 2011 at 09:09:42
nevermind I found exactly what I need. For anyone interested here is the code (thanks to CMarini):

@echo off
setLocal EnableDELAYedExpansion

for /d %%x in (*.*) do (
call :Rename %%x
goto End

:Rename %*
set DirName=%*
set count=1
echo Initial count: %count%
for %%f in ("%DirName%\*") do (
if !count! equ 1 ren "%%f" "%DirName%%%~xf"
if !count! gtr 1 ren "%%f" "%DirName% (!count!)%%~xf"
set /a count+=1
echo Incremented count: %count%
exit /b

For big time noobs, just paste into a .txt file, save as .bat and place the .bat file in the main directory and open the .bat file.

Report •
Related Solutions

Ask Question