Rename files in folder to folder name + .ext

December 7, 2010 at 18:18:54
Specs: Windows 7
Hey all,

I have been reading a lot of similar requests, but don't know enough about batch scripting to apply that knowledge to my situation.

I want a script that will recursively go through folders that are in the same directory as it, and rename and files called 'folder.jpg' it finds to be the name of the folder that this jpg file is in.

Example:

I want

C:\Movies\Salt [2010]\folder.jpg

to be renamed to

C:\Movies\Salt [2010]\Salt [2010].jpg

and also be able to span through any other folders that are in the Movies folder and do the same thing.

I know it can be done, but I am not sure how to do it myself.

Thanks all.


See More: Rename files in folder to folder name + .ext

Report •

#1
December 9, 2010 at 09:39:16
Try this...
run this batch file from the movies folder or parent of movies

@echo off & setlocal enabledelayedexpansion
cd /d c:\movies
for /f "tokens=* delims=\" %%a in ('dir /b /s folder.jpg') do (
for /f "tokens=3 delims=\" %%b in ("%%a") do ren "%%b\folder.jpg" "%%b.jpg"
)

Thanks.

Subhash Chandra.


Report •

#2
December 9, 2010 at 20:48:28
Hey there,

Thanks for that.

I have tried this code, but nothing appears to happen.

I changed the code to reflect my directory structure, and have this:

@echo off & setlocal enabledelayedexpansion
cd /d "g:\my videos"
for /f "tokens=* delims=\" %%a in ('dir /b /s folder.jpg') do (
for /f "tokens=3 delims=\" %%b in ("%%a") do ren "%%b\folder.jpg" "%%b.jpg"
)

But it doesn't appear to do anything. Any thoughts?


Report •

#3
December 10, 2010 at 06:55:50
put that batch file in the G:\my videos folder and run it..

if still not working then chage echo off to echo on and then post the output here.

Subhash Chandra.


Report •

Related Solutions

#4
December 10, 2010 at 19:54:01
Fixed it. I had the directory structure one level too deep for the code. Changed the code to:

@echo off & setlocal enabledelayedexpansion
cd /d "g:\my videos\movies"
for /f "tokens=* delims=\" %%a in ('dir /b /s folder.jpg') do (
for /f "tokens=4 delims=\" %%b in ("%%a") do ren "%%b\folder.jpg" "%%b.jpg"
)

And ran that file from within the Movies folder, and it worked perfectly.

Thanks :)


Report •

#5
December 13, 2010 at 07:01:50
Glad to see you have done it !! you are the man :)

Subhash Chandra.


Report •

Ask Question