Page 1 of 1
Renaming multiple files within folder(s)
Posted: 01 Sep 2011 07:21
by wlmpilot
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
Re: Renaming multiple files within folder(s)
Posted: 01 Sep 2011 10:10
by !k
?why not _http://www.mp3tag.de/en/
Re: Renaming multiple files within folder(s)
Posted: 01 Sep 2011 11:21
by wlmpilot
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.
Re: Renaming multiple files within folder(s)
Posted: 01 Sep 2011 11:28
by aGerman
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
Re: Renaming multiple files within folder(s)
Posted: 01 Sep 2011 11:55
by wlmpilot
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.
Re: Renaming multiple files within folder(s)
Posted: 01 Sep 2011 12:35
by !k
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
Re: Renaming multiple files within folder(s)
Posted: 01 Sep 2011 12:52
by aGerman
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
Re: Renaming multiple files within folder(s)
Posted: 01 Sep 2011 13:00
by !k
aGerman wrote:setlocal enabledelayedexpansion
trouble with exclamation marks in names
ex. "After School - Bang!.mp3"
Re: Renaming multiple files within folder(s)
Posted: 01 Sep 2011 13:14
by aGerman
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
Re: Renaming multiple files within folder(s)
Posted: 01 Sep 2011 13:49
by !k
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 (
Re: Renaming multiple files within folder(s)
Posted: 01 Sep 2011 14:36
by wlmpilot
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.