forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

fioDread in alphabetical order?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development
View previous topic :: View next topic  
Author Message
kouky



Joined: 25 Sep 2007
Posts: 48
Location: London

PostPosted: Sat Jan 24, 2009 2:44 am    Post subject: fioDread in alphabetical order? Reply with quote

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
View user's profile Send private message Visit poster's website
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Sat Jan 24, 2009 7:55 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
kouky



Joined: 25 Sep 2007
Posts: 48
Location: London

PostPosted: Sat Jan 24, 2009 8:30 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Sat Jan 24, 2009 10:20 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group