Computing.Net > Forums > Disk Operating System > Mass renaming in a batch

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Mass renaming in a batch

Reply to Message Icon

Name: Matthew Yauch
Date: February 27, 2003 at 19:37:55 Pacific
OS: Windows XP
CPU/Ram: Athlon 800/256MB
Comment:

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.mp3

I want to rename EVERY mp3 to this format:
Track# - Trackname.mp3

I 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!



Sponsored Link
Ads by Google

Response Number 1
Name: Moondragon
Date: February 28, 2003 at 17:43:15 Pacific
Reply:

Another option is to use
renamefiles v2.2
www.alatar.de

J


0

Response Number 2
Name: Secret_Doom
Date: February 28, 2003 at 19:46:09 Pacific
Reply:

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

_____________________________________________________________


0

Response Number 3
Name: Secret_Doom
Date: February 28, 2003 at 19:48:31 Pacific
Reply:

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


0

Response Number 4
Name: Matthew Yauch
Date: March 6, 2003 at 15:35:35 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Mass renaming in a batch

Rename in a Batch file www.computing.net/answers/dos/rename-in-a-batch-file/12873.html

Max Line Length in a batch file www.computing.net/answers/dos/max-line-length-in-a-batch-file/9738.html

want specify enter in a batch file www.computing.net/answers/dos/want-specify-enter-in-a-batch-file/14558.html