Site menu:

Categories

Tags

Site search

 

March 2008
M T W T F S S
« Feb   Apr »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Archives

Links:

iRiver S10 sorting

Or rather lack of. My shiny new toy has one astoundingly bad bug - it doesn’t sort filenames - at all. So albums often play in a random order - track 4, then track 10, then track 1 (if that’s the order they happen to be in the filesystem).

To be honest I find it gobsmacking that this has shipped with this bug, let alone the fact that they still havn’t fixed it.

So I’ve written this script to fix this up. The first version used “touch” as I thought they were using modified time but of course that isn’t right - since the filesystem may re-use earlier entries. So now I use a bunch of “move” commands instead. Use this program like this: “iriversort /mnt/Music”:


#!/bin/sh

# The iRiver S10 doesn't sort files on it
# it just displays them in directory order!

# Copyright 2008 Adrian Bridgett
# Released under GPL v3

usage()
{
cat < Usage: `basename $0` directory

Recursively sorts directories by ensuring last modified timestamp
is in alphabetical order
EOF
}

die()
{
echo "$@" >&2
exit 1
}

scan()
{
local dir=”$1″
dir=${dir%/}
mv “$dir” “$dir.old” || die “Unable to rename $PWD/$dir”
mkdir “$dir” || die “Unable to create directory to $PWD/$dir”
local i
ls -f “$dir.old” |sort |while read i; do
case “$i” in
“.”) continue;;
“..”) continue;;
esac
if [ -d "$dir.old/$i" ]; then
scan “$dir.old/$i”
fi
mv “$dir.old/$i” “$dir/” || die “Unable to move $PWD/$dir.old/$i back”
done
rmdir “$dir.old” || die “Unable to remove $PWD/$dir.old”
}

if [ $# != 1 ]; then
usage
fi

root=”$1″
special case for . required
if [ "$root" = "." ]; then
die “Unable to move current directory - use full path”
fi
scan “$1″

Write a comment