Link to home
Start Free TrialLog in
Avatar of grantwatson
grantwatsonFlag for New Zealand

asked on

Rename mutlible files

Hi All,

i have a number of subfolders that contain JPG's that are all named differently, i want the batch file to locate each one and rename each one to cover.jpg

Can someone throw together a dirty bacth file that would allow me to do this quickly. i have 300+ JPGs to rename, i dont want to do them manually...

I can run the batch file on either XP or 2000.

thanks

Grant
Avatar of daVinceV
daVinceV

you can use the 'for' command: This works typed from command line if your directories with the images do not contain subdirectories. Renaming all files in the directories to cover.jpg will not work if there is more than 1 jpg - "rename /F" (for forece overwrite) is not supported.

cd directoryContainingTheSubdirectoriesWithTheImages
for /D %d in (*) do ( cd %d <ENTER>                           REM You will be asked 'more?' - just type on
for %f in (*) do rename %f cover.jpg <ENTER>            REM Once again 'more?'
cd .. <ENTER>
) <ENTER>

If you need more complex scripting (perhaps for the recursion for sub-subdirectories) I'd recommend PERL or any other scripting language. I think MS says that WindowsScriptingHost WSH should be used for purposes like this.

Best regards,
Vince
Try this:

@for /R c:\ %%f in (*.jpg) do echo rename "%%~ff" cover.jpg

Good Luck,
Steve
ASKER CERTIFIED SOLUTION
Avatar of SteveGTR
SteveGTR
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of grantwatson

ASKER

Ummm....

daVinceV yours works, excepting i have mutlible levels of folders, your example only drops one level..

SteveGTR yours come up with a error message "%%f was unexpected at this time."

If you ran it from the command line that will happen. The above code was meant to run from within a batch file (.bat).

To run it from the command line do this:

@for /R c:\ %f in (*.jpg) do rename "%~ff" cover.jpg
thanks SteveGTR

played around with the sytax and it appears to be going to work...

thanks to you both
correct... thanks again
SteveGTR, i used your example with a few changes and saved it to a batch file. Instead of renaming .jpg I'm trying to rename .txt.

rename.bat
----------------------------
@for /R C:\Documents and Settings\folder\folder\datafile %%f in (*.txt) do rename "%%~ff" dataFile.txt
----------------------------

I don't think I know enough about batch programming to get this to work. I ran the batch file as is and the files I wanted to convert to 'datafile.txt' didn't convert. Can you tell me if what I have is correct and if not, what changes should I make?

Where you have "c:\" I'm supposed to place my directory right?
Instead of *.jpg i want to convert text files so I used .txt, is that ok?

Any help would be great, thanks.

You should open up a new question and reference this question. There are many helpful experts that will assist you :)