Log in

View Full Version : Sort Filename Algo ?


Dark-Cracker
21st August 2004, 00:52
hum i hope this question doesn't sound too silly :) but i fact i am asking myself if there is an algo to sort the filename.

for example if u have the file :

toto1.txt toto2.txt toto10.txt toto20.txt

a genetical sort funtion will sort them like this :

toto1.txt / toto10.txt / toto2.txt / toto20.txt

of course if u use the ascii code to compare them it will have some problems if instead of toto1.txt u have toto01.txt

so my question is : there is an algo to sort ascendent filename whith numeric part ?

Bye.

GaveUp
21st August 2004, 02:44
Well in perl you could use a regex on the filename to extract the 'name' and the 'number' .. then it'd just be a matter of comparing.

ssjkakaroto
22nd August 2004, 15:47
hey there Dark-Cracker, i'm no programmer but i think this might help you: http://sourcefrog.net/projects/natsort/

Dark-Cracker
22nd August 2004, 18:00
thank u i think this should help me much :)

++