I've this code to list all file in a directory and alphasort the file printed, but the file are listed in the same position as the directory, but i want list the file with this sequence:
Just sorting by name isn't going to get you anywhere as readdir() does not guarantee any order for the items returned. When you sort you'll have to consider type (dir/file) first, then name.
IIRC, stat() requires an absolute file name so once you read the entry with readdir() insert some function which obtains the type then pass this and the actual name to the comparator.
Well thanks for putting me onto qsort. I never knew about it.
I used this to sort an array of strings (file paths) for my mp3 browser: http://www.c.happycodings.com/Sorting_S ... ode16.html
(already had the strings in memory of course).
Doesn't help with the thread starters' problem sorry.
Art.
Funny one of my first botched attempts treats the path strings as integers or something,
and is a good way to seemingly randomise an mp3 playlist without copying into a duplicate
buffer or anything, then you can just alpha sort them properly again.
What a bonus :) But it's the same every time,
so I think I'll go for randomising the selection numbers and go from there.
I knew I wasn't dealing with many files, so I just did my own simple bubble sort in Doom's file requester. It sorts directories first, and everything alphabetically. Sorting is one of those things you get like the first week of any programming class. It's not a big deal. :)