Linux: sorting files on SD card

General discussion forum - for all that doesn't fit in any other category.
Post Reply
Strider
Posts: 12
Joined: Sun Oct 22, 2006 10:32 pm

Linux: sorting files on SD card

Post by Strider »

Hi there,

If you are running Linux here is a little script to sort recursively your files on your SD card (of course it also works with any storage):

Code: Select all

#!/bin/sh

# Usage:
# findalpha [-R]

# Reorder the directory entries according to alphanumerical order, so
# find output is in order.  Useful for preparing files for play on an
# MP3 player that follows directory order.
# If -R is given, do recursively.

# Thu Dec 27 02:47:00 EST 2007 v. 0.1 jh initial version
# Wed Oct 22 11:08:00 EST 2008 v. 0.2 andrew-regner added support for directories with spaces

# TODO:
# figure out why it works on IDE but not on USB, even if the FS is ext3

start="`pwd`"

if [ "$1" = "-R" ] ; then
  dirs=`find . -type d`
else
  dirs=.
fi

for dir in $dirs; do
  test "$sdir" != "" && dir="$sdir $dir"
  if [ ! -d "$dir" ]; then
    sdir="$dir"
    continue
  fi
  cd "$dir"
  tmp=`mktemp -d -p .`
  find . -maxdepth 1 -mindepth 1 | grep -v $tmp | xargs -n1 -d"\n" -I'{}' mv '{}' $tmp
  cd $tmp
  find . -maxdepth 1 -mindepth 1 | sort -n | xargs -n1 -d"\n" -I'{}' mv '{}' ..
  cd ..
  rmdir $tmp
  cd "$start"
done
Save it (as root if necessary) for example in /usr/bin/findalpha

Usage is quite simple: open a terminal, change the current directory to the one you want to sort. Then just type "findalpha". Or type "findalpha -R" to sort recursively.
Example:

Code: Select all

~$ cd /media/HXC/
/media/HXC$ findalpha -R
Information was taken from this site: http://www.linuxforums.org/forum/newbie ... ctory.html-R

pulkomandy
Posts: 132
Joined: Sun Mar 20, 2011 6:55 pm

Re: Linux: sorting files on SD card

Post by pulkomandy »

Code: Select all

apt-get install fatsort

http://fatsort.sourceforge.net/

Strider
Posts: 12
Joined: Sun Oct 22, 2006 10:32 pm

Re: Linux: sorting files on SD card

Post by Strider »

Oh thanks, I didn't know this is one existed :oops:

serge35
Posts: 1
Joined: Wed Sep 19, 2012 10:50 pm
Location: saint-malo

Re: Linux: sorting files on SD card

Post by serge35 »

Bonjour à tous je suis nouveau sur ce forum "désolé je n'est pas trouvé la section de présentation".
Je suis moi même sous linux ( ubuntu 11.04 ) j'ai constaté que le soft fonctionne très bien sous WINE que l'on trouve dans la logithèque ou via la console " apt-get install WINE " enfin bon , de ce côté la je ne vous apprends rien. J'ai pu sans mal convertir mes fichiers DSK en HFE pour mon CPC 6128 . bonne fin de semaine.

Post Reply