There is a way to rsync a m3u playlist into a destination directory.

How can I process the list and number the output so it orders the files to match the playlist order?

For example the m3u:


would copy/rsync the playlist contents, renaming the files to:


This is so I can build mixtape playlists and copy them for people.

Any advice appreciated.


Try something like this:


FILE = '/home/my-home/my-playlist.m3u'
DIR = '/some-target-directory'

import os.path, shutil, sys

for i, s in enumerate(open(FILE)):
    s = s.rstrip()
        shutil.copy(s, os.path.join(DIR, '%03d-%s' % (i+1, os.path.basename(s))))
    except IOError, e:
        sys.stderr.write('warning: %s\n' % e)

# End of file.

Obviously, set FILE and DIR to what you need. Apologies for going over the top and using Python for this — it helps not to have to escape all those characters shells love to attach special meanings to.

The script won't fail on I/O errors, it'll just output a warning. Other than that, there are no sanity checks (as you can probably see). Nor does it exclude M3U comments. It'll happily copy any character you throw at it, though, with the obvious exceptions of NULs and slashes which are special characters at the filesystem level.

  • This is perfect, I like the Python as I'm keen on learning it. Thanks! – invert Feb 2 '12 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.