Renaming multiple files within folder(s)

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
wlmpilot
Posts: 4
Joined: 01 Sep 2011 07:10

Renaming multiple files within folder(s)

#1 Post by wlmpilot » 01 Sep 2011 07:21

In my music directory, I have several folders, ie Beach Music, Country, Classic Rock, etc. Within each of these folders are music files (mp3) with the current format as the filename:

group - songtitle.mp3 ie Beach Boys - California Girls.mp3
(the file extension .mp3 does not appear under the name column of the directory)

I would like to go through each mp3 file I have that has this name format and remove everything prior to the actual songtitle so that "Beach Boys - California Girls" would be renamed to "California Girls".

How can I do this in a batch file? I use Windows 7.

Thanks

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: Renaming multiple files within folder(s)

#2 Post by !k » 01 Sep 2011 10:10

?why not _http://www.mp3tag.de/en/

wlmpilot
Posts: 4
Joined: 01 Sep 2011 07:10

Re: Renaming multiple files within folder(s)

#3 Post by wlmpilot » 01 Sep 2011 11:21

Was not aware of that. However, I like programming and learning it. Just figure a simple batch file would accomplish what I need to do.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Renaming multiple files within folder(s)

#4 Post by aGerman » 01 Sep 2011 11:28

Is it always a combination of space|hyphen|space that separates the group from the song title? Can you make sure that this combination exists only once in a file name?

Regards
aGerman

wlmpilot
Posts: 4
Joined: 01 Sep 2011 07:10

Re: Renaming multiple files within folder(s)

#5 Post by wlmpilot » 01 Sep 2011 11:55

Yes, everyone currently has the format for the filename using " = ", ie space hypen space.

The name of the artist or group is first with the song title following. They are separated with " - ", examples

Beach Boys - California Girls
Beach Boys - Barbara Ann
Chairman of the Board - Be Young, Be Foolish

I want to remove everything prior to the song title, including the space just before the song title.

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: Renaming multiple files within folder(s)

#6 Post by !k » 01 Sep 2011 12:35

run in root directory

Code: Select all

for /f "tokens=1,2* delims=-" %%a in ('dir /a-d/b/s "* - *.mp3"') do (
set "name=%%b"
call ren "%%~dpna -%%b" "%%name:~1%%"
)

no hyphen in dir's names allowed

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Renaming multiple files within folder(s)

#7 Post by aGerman » 01 Sep 2011 12:52

Similar:

Code: Select all

@echo off &setlocal
for /f "delims=" %%a in ('dir /a-d /b /s "* - *.mp3"') do (
  set "oldname=%%~nxa"
  setlocal enabledelayedexpansion
  for /f "tokens=1* delims=?" %%b in ("!oldname: - =?!") do (
    ren "%%a" "%%c"
  )
  endlocal
)
pause

hyphens in folder names allowed

Regards
aGerman

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: Renaming multiple files within folder(s)

#8 Post by !k » 01 Sep 2011 13:00

aGerman wrote:setlocal enabledelayedexpansion
trouble with exclamation marks in names
ex. "After School - Bang!.mp3"

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Renaming multiple files within folder(s)

#9 Post by aGerman » 01 Sep 2011 13:14

Haha you won, !k.
Lets write a code with the best of both.

Code: Select all

@echo off &setlocal
for /f "delims=" %%a in ('dir /a-d /b /s "* - *.mp3"') do (
  for /f "tokens=1* delims=-" %%b in ("%%~nxa") do (
    set "name=%%c"
    call ren "%%a" "%%name:~1%%"
  )
)

Regards
aGerman

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: Renaming multiple files within folder(s)

#10 Post by !k » 01 Sep 2011 13:49

private message wrote:Does the batch file need to be in the directory of the files being renamed. If not, where do I indicate the path?


for /f "delims=" %%a in ('dir /a-d /b /s "D:\My Music\* - *.mp3"') do (

wlmpilot
Posts: 4
Joined: 01 Sep 2011 07:10

Re: Renaming multiple files within folder(s)

#11 Post by wlmpilot » 01 Sep 2011 14:36

Thanks for the code. I tried Expert's first and it works great. Did not try aGerman's. Thank you both for your time and contribution to my question.

Post Reply