Sunday, December 14, 2008

Copying music files in a playlist to a different folder

A friend of mine had his music collection managed by iTunes. He had many playlists, pointing to music files in deeply nested folders. This was the requirement - he wanted to fish out all the songs pointed to by one of his playlists, and copy them to a certain directory.

Playlist is usually a plain text file where each line of the file points to the full or relative path of the music content.

For example, 

c:\documents and settings\music\album1\a.mp3
c:\documents and settings\music\ album2\b.mp3
c:\documents and settings\music\ album3\c.mp3

could be the contents of a file called myplaylist.m3u. Also, it is possible that there are "comments" in the file (comments are lines prefixed with #).

Here is a quick and dirty solution I came up with to do this copy -

Fire up notepad, type the following:

for /F "delims=" %%a in ('type %1') do copy "%%a" %2

and save it in a file called playlistcopy.bat. Preferably, put it in the same folder as your play list file (this is to make sure that things still work if your playlist uses relative paths).

Now open a dos prompt, change to the directory where you saved the batch file, type the following and press enter:

playlistcopy.bat "c:\documents and settings\itunes\myplaylist.m3u" "c:\temp"

Replace the first argument with the location of your play list file, and the second argument with any other directory you want the music to be copied to (just make sure that directory exists).

This is not a fool proof way, because if there are comments in your playlist, you will see some errors. That is OK though, those errors won't hurt anything.

Simple, eh?

No comments: