| View previous topic :: View next topic |
| Author |
Message |
kouky

Joined: 25 Sep 2007 Posts: 48 Location: London
|
Posted: Sat Jan 24, 2009 2:44 am Post subject: fioDread in alphabetical order? |
|
|
Hi, I am using the fioDread to scan and display the content of a folder from an USB drive.
But it looks like fioDread sort files by date, and I wish it could sort files by alphabetical order.
Is there a way to do it?
this is the code I'm using:
| Code: |
while (fioDread(ret, &record) > ) { ... }
|
_________________ softwares for artists on video game systems - http://www.pikilipita.com |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Sat Jan 24, 2009 7:55 am Post subject: |
|
|
Most directory return services return entries in the order they're found in the filesystem structure. Given that most file managers copy by date (when you copy the next file over, it's a later date - even if only by a few seconds), those entries are likely to be "sorted" by date when read back.
If you want entries sorted by something other than the order they exist in the directory, you generally have to sort the entries by hand after reading them. You'll see that in all sorts of apps. If you read the entries into a linked list, you could sort by name while reading the entries by inserting the node according to the name. |
|
| Back to top |
|
 |
kouky

Joined: 25 Sep 2007 Posts: 48 Location: London
|
Posted: Sat Jan 24, 2009 8:30 am Post subject: |
|
|
Oh my god!
That's gonna be tough job to write bymyself code to sort it by alphabetical order...
Thanks for your quick reply _________________ softwares for artists on video game systems - http://www.pikilipita.com |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Sat Jan 24, 2009 10:20 am Post subject: |
|
|
| kouky wrote: | Oh my god!
That's gonna be tough job to write bymyself code to sort it by alphabetical order...
Thanks for your quick reply |
It's not THAT tough! Here's my sort routine used in Doom on the PSP after I load the entries from the current directory.
| Code: | // sort them!
for (i=0; i<maxfiles-1; i++)
{
char tempfilename[FILENAME_MAX];
char temppath[FILENAME_MAX];
int tempflags;
if ((!thefiles[i].flags && thefiles[i+1].flags) || // directories first
(thefiles[i].flags && thefiles[i+1].flags && strcasecmp(thefiles[i].filename, thefiles[i+1].filename) > 0) ||
(!thefiles[i].flags && !thefiles[i+1].flags && strcasecmp(thefiles[i].filename, thefiles[i+1].filename) > 0))
{
strcpy(tempfilename, thefiles[i].filename);
strcpy(temppath, thefiles[i].path);
tempflags = thefiles[i].flags;
strcpy(thefiles[i].filename, thefiles[i+1].filename);
strcpy(thefiles[i].path, thefiles[i+1].path);
thefiles[i].flags = thefiles[i+1].flags;
strcpy(thefiles[i+1].filename, tempfilename);
strcpy(thefiles[i+1].path, temppath);
thefiles[i+1].flags = tempflags;
i = -1;
}
}
|
It's pretty much just a really simple bubble sort. Not the fastest thing in the world, but you won't notice the time on anything short of several hundred files. :)
The next time I update this, I'll probably switch to a linked list instead of an array, and do the sort on the fly. |
|
| Back to top |
|
 |
|