Copy and Rename .mp3 Files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ChumpChange350
Posts: 2
Joined: 03 Jun 2009 22:28

Copy and Rename .mp3 Files

#1 Post by ChumpChange350 » 03 Jun 2009 22:52

For about two days now I've been trying my hand at making a Windows XP batch script designed to copy and rename .mp3 files from one location to the other without any significant luck. In detail, I'm attempting to select multiple mp3 files with the name format "ARTIST - TRACKNAME" from a singular music directory and drag them over the batch file so that they can be copied to the same location as the batch file, only organized into folders starting with the mp3's artist, then album, then "TRACKNUMBER TRACKNAME" for the copy's new file name. This is my first foray into making Windows batch files so I've been trying to make a simple batch and build it up as I go. So far, I have this:

Code: Select all

@echo off
@setlocal EnableDelayedExpansion
@FOR %%I IN (%*) DO (xcopy %%I .\Music /C /D /H /I /K /Q /R /Y)
pause


Already, however, two issues are very prevalent. First, I can not pass files in by dragging and dropping them over the batch script icon. For every file I try to use like this the script prints out "Invalid number of parameters". Secondly, despite the /I and /Y tags on the xcopy function, the batch prompts me to choose whether or not any unmade directories should be files or directories. Can I not automate this so the decision should automatically be for directories? Thanks for all the help in advance.

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 04 Jun 2009 11:52

/i works only for xcopy'ing multiple files (like with a wildcard). The for loop copies 1 file at a time, so the /i is ignored (don't ask me why -- ask Microsoft).

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#3 Post by avery_larry » 04 Jun 2009 11:58

.\Music probably won't work. The current working directory of the batch file is not likely to be the same as your batch file.

Use:

cd /d "%~dp0"

to get the directory containing the batch file to be the current working directory.

Note here that you can also manually create the subdirectory instead of relying on the /i switch

ChumpChange350
Posts: 2
Joined: 03 Jun 2009 22:28

#4 Post by ChumpChange350 » 04 Jun 2009 13:21

Avery, thanks for your help. It's cleared up a lot of things for me. Also, I've solved the problem in automatically creating the subdirectories... It was lacking a trailing slash... Ugh.
For the sake of an update, I was able to improve the code in general and here's it's current form:

Code: Select all

@echo off
setlocal EnableDelayedExpansion
cd /d "%~dp0"
FOR %%I IN (%*) DO (
if %%~xI==.mp3 (
xcopy %%I .\Music\ /C /D /H /K /Q /R /Y
) else echo FILE IS NOT AN MP3: %%I)
pause


Now I basically just have to learn how to read file properties and use them in the xcopy command and eventual ren command that I'll be using. It seems these properties are available in the SummaryInformation and DocumentSummaryInformation values for each file (source), but I have to do more work on it all. Seems really tricky, but hopefully I'll get it down with some time.

Post Reply