Sorting Music Player Files

Some portable music players (including mine) sort tracks in the sequence they were added to the player rather than alphabetically. I find this annoying and had been using a time-consuming method to alphabetize the files on my player. David Fletcher posted a better method to the kubuntu-users mailing list in November 2007, which I subsequently modified.
The general concept is to create an image of the player's contents on the hard drive and to then use the rsync command to synchronize the player with the disk image.
Note the following:
  • My disk image is located at /extra/MUSIC
  • My player has a top level directory also named MUSIC
  • My player mounts as /media/usbdisk
I created a shell script with the following contents:
rsync --verbose --recursive --times --whole-file \
--delay-updates --modify-window=1 --delete-before \
/extra/MUSIC/ /media/usbdisk/MUSIC/
Be sure to change the paths to the disk image and the player's music directory as appropriate for your system. Also, be sure to make the script executable.
With this setup, I can now do the following:
If I delete files/directories from the hard disk image and run the script, the associated files/directories will be deleted from the player.
If I add files/directories to the hard disk image and run the script, the associated files/directories will be added to the player. Everything that's copied in a given batch will be processed in alphanumeric sequence.
This is not a perfect solution. Let's say I have an album directory on the player and in the disk image that contains tracks 1, 2 and 4. If I now add track 3 to the disk image and run the script, the track order on the player will be 1, 2, 4, 3. My workaround is to first delete the enclosing directory from the player and to then run the script. The entire directory will then be re-copied to the player, with the tracks in sequence. The same concept can also be used at higher directory levels, if desired.
Last Updated: February 28, 2008