1.

Solve : How to create a batch command to change file names?

Answer»

Hi
I have a folder of 1000s of mp3 files with names in the following format:

02 Zenaida aurita.mp3
01 - Red-throated Loon.mp3

What I want to do is create a dos command that trawls through the folder and removes the 02, 01, - and initial space before the actual name so that I end up with just (Zenaida aurita.mp3). I want to do this for every file in the folder. Bear in mind that it is not just 01 OR 02. The files have any number at the beginning such as 099. However, I do not want any numbers at the end of the file name removed so some files are like this:

38 Black-chinned Mountain-Tanager (2).mp3

and this one should end up LOOKING like this:

Black-chinned Mountain-Tanager (2).mp3

Any help and ideas?This works here:

Filenames with % and ^ in them might give problems, and foreign language character sets.

Code: [Select]@echo off
del renmp3.bat.txt 2>nul
for %%a in (*.mp3) do (
for /f "tokens=1,2,* delims= " %%b in ("%%a") do (
for /f "delims=0123456789" %%e in ("%%bA") do (
if "%%e"=="A" (
if "%%c"=="-" (
>>renmp3.bat.txt echo ren "%%a" "%%d"
) else (
>>renmp3.bat.txt echo ren "%%a" "%%c %%d"
)
)
)
)
)
echo check renmp3.bat.txt for issues, if it's ok rename it .bat and run it.
pause
Quote

Hi foxidrive
Thanks, this worked brilliantly and did the job for the majority of the files. Much appreciated as it SAVED me huge work. There was one problem in that I discovered files with the hyphen sandwiched between numbers i.e.

099 - 01 BLACKBIRD.MP3
there were 100s of this type that the dos code did not rename. Is there an alteration to the code you can suggest to do this type?

Thanks again.

This is UNTESTED: it works in the same way. The REN commands will be placed in the file for you to examine.

If you have files like

109-03 title.mp3 (without spaces between the numbers and hyphens) then you'll need another variation.

Code: [Select]@echo off
del renmp3.bat.txt 2>nul
for %%a in (*.mp3) do (
for /f "tokens=1,2,3,* delims= " %%b in ("%%a") do (
for /f "delims=0123456789-" %%f in ("%%b%%c%%dA") do if "%%f"=="A" >>renmp3.bat.txt echo ren "%%a" "%%e"
)
)
echo check renmp3.bat.txt for issues, if it's ok rename it .bat and run it.
pause
These solutions have worked great. Thanks for all the help. I have converted over 6500 names in a SECOND which as you can imagine was not a manual task I would have liked.

Very very much appreciated. Thanks


Discussion

No Comment Found