Need CMD To Rename MP3 Files

June 20, 2015 at 00:31:53
Specs: Windows 7
Need CMD To Rename MP3 Files
Change Case To Capitalize Each Word Case
Rename " And " to " & "
Remove Extra Spaces In The Filename
Replace _ with a space
Remove All (whatever) and [whatever] in filenames
Replace &39; Example Don&39;t to Don't

See More: Need CMD To Rename MP3 Files

Report •

#1
June 20, 2015 at 00:33:25
@echo off
Setlocal enabledelayedexpansion
Set "Pattern1= And "
Set "Replace1= & "

Set "Pattern2=&39;"
Set "Replace2='"

Set "Pattern3=_"
Set "Replace3= "

Set "Pattern4=-."
Set "Replace4=."

Set "Pattern5= "
Set "Replace5= "

Set "Pattern6= ."
Set "Replace6=."

Set "Pattern7=["
Set "Replace7=("

Set "Pattern8=]"
Set "Replace8=)"

For %%# in ("*.mp3") Do (
Set "File=%%~nx#"
Ren "%%#" "!File:%Pattern1%=%Replace1%!"
Ren "%%#" "!File:%Pattern2%=%Replace2%!"
Ren "%%#" "!File:%Pattern3%=%Replace3%!"
Ren "%%#" "!File:%Pattern4%=%Replace4%!"
Ren "%%#" "!File:%Pattern5%=%Replace5%!"
Ren "%%#" "!File:%Pattern6%=%Replace6%!"
Ren "%%#" "!File:%Pattern7%=%Replace7%!"
Ren "%%#" "!File:%Pattern8%=%Replace8%!"
)

Set "Pattern5= "
Set "Replace5= "

For %%# in ("*.mp3") Do (
Set "File=%%~nx#"
Ren "%%#" "!File:%Pattern5%=%Replace5%!"

)

Set "Pattern5= "
Set "Replace5= "

For %%# in ("*.mp3") Do (
Set "File=%%~nx#"
Ren "%%#" "!File:%Pattern5%=%Replace5%!"

)
for %%f in (*) do (
set "filename=%%~f"

for %%A in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
set "filename=!filename:%%A=%%A!"
)
ren "%%f" "!filename!" >nul 2>&1
)
for %%F in (*.*) do (
set "original=%%F"
set "name= %%~nF"
set "ext=%%~xF"
setlocal enableDelayedExpansion
for %%C in (
A B C D E F G H I J K L M
N O P Q R S T U V W X Y Z
) do set "name=!name: %%C= %%C!"
set "name=!name:~1!"
ren "!original!" "!name!!ext!"
)
endlocal

set odd=1,3,5,7,9,11,13
set evn=2,4,6,8,10,12,14
:: ignore any files with no parens
for /f "tokens=*" %%a in ('dir /b *(*.mp3') do (
set x=%%a
:: is ths really necessary? or "overkill". Attempts to hande files beginning with (
set t=!x:~0,1!
set x=!x:^)^(=!
if "!t!" equ "(" (
for /F "tokens=%evn% delims=()" %%b in ("!x!") do ren "%%a" "%%b%%c%%d%%e%%f%%g%%h"
) else (
for /F "tokens=%odd% delims=()" %%b in ("!x!") do ren "%%a" "%%b%%c%%d%%e%%f%%g%%h"
)
)


Report •

#2
June 20, 2015 at 00:51:27
@echo off
Setlocal enabledelayedexpansion
SET "sourcedir=*.*
FOR /f "delims=" %%a IN (
'dir /b /s /a-d "*" '
) DO (
SET "name=%%~na"
SETLOCAL ENABLEDELAYEDEXPANSION
SET "newname=!name:]= ) !"
SET "newname=!newname:[= ( !"
IF "!name!" neq "!newname!" (
IF EXIST "%%~dpa!newname!%%~xa" (RENAME %%a
) ELSE (REN "%%a" "!newname!%%~xa")
)
endlocal
)

Replace [] with () Works Better ... Replaces Pattern 7 and Pattern 8
I could remove 2 sets of () in a filename without a problem
but 2 [] in a filename was not working...
so I changed [] to () so that 2 () would be removed and the code works
... so that solved that problem.

message edited by TekWiz2001


Report •

#3
June 23, 2015 at 17:13:30
Would you listen to me if I told you this was easier in literally any other scripting language with proper string support?

How To Ask Questions The Smart Way


Report •
Related Solutions


Ask Question