Georgie Q
Georgie Q

Reputation: 19

How do I rename a file to the same name as the folder it is in?

I found similar questions, but to be honest it's all way over my head, and also not exactly what I want.

So, I have over 300 folders that are named, example:

Superstuff/notsuperstuff.jpeg
Othername/notothername.jpeg
randomwords/notrandomwords.jpeg.

I would like the Jpegs to be renamed as the folder. so: Superstuff/Superstuff.jpeg etc...

btw, I'm using Windows 7, I think batch scripting could do this? Not sure.

Thanks in advance everyone!! Cheers

Upvotes: 0

Views: 1163

Answers (1)

Suda
Suda

Reputation: 245

Assuming that you are in the Root Folder (Folder with all the Other Folders),
Don't append @echo off to the batch file if you want to make sure that all is going well.

for /r %%F in (*.jpeg) do @for %%A in ("%%F\..") do ren "%%F" "%%~nxA.jpeg"

Detailed clarification on command coming soon.
And as always with the Command Line, Bakup your files before doing anything :)

P.S. Tested, And it works. If using directly in CMD, change the double Percentages to Single Percentages (%%A > %A)

Upvotes: 1

Related Questions