Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Okie dokie. I'm sure SOMEONE will laugh at this, but that's okay. I have a directory, say MP3s, with many more directories of artist names, and within those are directories for album names, and of course within those are mp3s. So what we have is alot of:
C:\MP3s\artists\albums\mp3s.mp3
Unfortunately these mp3s aren't called nice names, they ugly ones such as
joesband_01_Track_Uno.mp3
or
joezbizand (01) Track Uno.mp3I want to rename EVERY mp3 to this format:
Track# - Trackname.mp3I just now figured out that I can use FOR /R to traverse an entire directory's subdirectories and execute a command, so I could nest this a couple times to get the results I want, but then how would I rename all of the files in a directory to an edited version of their current name? Is this even possible in DOS (I'll actually be using this batch file in WinXP)? If not, anyone know a way to traverse directories in Visual C++? Thanks a bunch just for reading!

For that task, me must find a criterion, a rule to define the new filenames. I think this rule will fit on your needs:
"considering tokens separated by spaces or underlines, the first numerical token, surrounded or not by parenthesis, will be %%A (excluding eventual parenthesis) and the rest of the tokens will be %%B, so the new filename is '%%A - %%B'."
This will do it:
@echo off
if "%1"=="GoTo" goto %2
%comspec% /v:on /c %0 GoTo start
goto eof:start
for /R C:\MP3 %%F in (*.mp3) do (
set F1=%%~nF
set F2=0
call %0 GoTo process
echo.ren "%%F" "!F2!%%~xF"
)
goto eof:process
if "%F1%"=="" goto eof
for /F "tokens=1* delims=_ " %%A in ("%F1%") do (
if "!F2!"=="0" (
set N=%%A
if "!N:~0,1!"=="(" if "!N:~-1!"==")" set N=!N:~1,-1!
set /A F2 = %%A
if not "!F2!"=="0" set F2=!N! -
) else (
set F2=!F2! %%A
)
set F1=%%B
)
goto process:eof
The script is de-activated. If you run it like that it will display the actions it would take if active. If those are the desired actions, activate the script by removing the string "echo." (in red on the post).
That script is compatible with Windows 2000, XP and probably NT also. It will fail on Win9x and DOS.
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br_____________________________________________________________

Hey, by the way, that source is for a batch script. Cut and paste it into a text file and name it with a .BAT extention, and then you can run execute it.
And I don't see anything funny on your post...
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br

Wow that batch script works very well! The only problem I've seen is if there's an odd character such as ' it has a problem, but that's easily done manually since those are fairly rare. I'd fix the script, but I don't understand half of it and I'm a little too impatient to learn another language right now haha. Thanks man!
I thought it might be funny that I only wanted a script to rename MP3s, but the more I think about it, that's WHY we program... to do things we don't want to waste LOTS of time on. Hmmm.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |