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, the hyphen 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 or hyphens in the middle of a name 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?
How to create a batch command to change file names
Moderator: DosItHelp
Re: How to create a batch command to change file names
Have ALL files a number at beginning? Or may be files with no number?
If all files haves numbers, this is the solution:
Antonio
If all files haves numbers, this is the solution:
Code: Select all
@echo off
setlocal EnableDelayedExpansion
for %%a in (*.mp3) do (
set "name=%%a"
rem Remove first characters until first space
set "name=!name:* =!"
rem Remove first hypen and space, if any
if "!name:~0,1!" equ "-" set "name=!name:* =!"
ren "%%a" "!name!"
)
Antonio
Re: How to create a batch command to change file names
He asked the same question elsewhere and I put this together. It handles ! characters but % could be an issue.
Code: Select all
@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