Sep
11
Updating timestamps of mp3 files alphabetically and recursively
Fri, 09/11/2009 - 16:35
The radio in my car has the strange habit of ordering the mp3 files on my USB stick by the timestamp of the files. This can give very unpredictable results, many albums play back in a seemingly random order. It would of course be much more logical if the radio would follow the track order given in the ID3 tags, or even simply order the files alphabetically as the filenames are often prefixed with the track numbers. I wonder at the logic behind this design decision.
I made a small BASH script that updates the timestamps in alphabetical order. This fixes the playback order.
#!/bin/bash
# This script updates the timestamps of all mp3 files in the current directory and all
# subdirectories in alphabetical order. It waits one second between every update.
#
# It also saves a list of all found mp3 files in the text file 'mp3-index.txt'
find | grep mp3 | sort > mp3-index.txt
cat mp3-index.txt | while read line;
do
echo "touching file $line"
touch "$line"
sleep 1
done

Post new comment