fioDread in alphabetical order?

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
User avatar
kouky
Posts: 48
Joined: Tue Sep 25, 2007 5:38 am
Location: London
Contact:

fioDread in alphabetical order?

Post by kouky »

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: Select all

while (fioDread(ret, &record) > ) {  ... }
softwares for artists on video game systems - http://www.pikilipita.com
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

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.
User avatar
kouky
Posts: 48
Joined: Tue Sep 25, 2007 5:38 am
Location: London
Contact:

Post by kouky »

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
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

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: Select all

	// sort them!
	for &#40;i=0; i<maxfiles-1; i++&#41;
	&#123;
		char tempfilename&#91;FILENAME_MAX&#93;;
		char temppath&#91;FILENAME_MAX&#93;;
		int tempflags;

		if &#40;&#40;!thefiles&#91;i&#93;.flags && thefiles&#91;i+1&#93;.flags&#41; || // directories first
			&#40;thefiles&#91;i&#93;.flags && thefiles&#91;i+1&#93;.flags && strcasecmp&#40;thefiles&#91;i&#93;.filename, thefiles&#91;i+1&#93;.filename&#41; > 0&#41; ||
			&#40;!thefiles&#91;i&#93;.flags && !thefiles&#91;i+1&#93;.flags && strcasecmp&#40;thefiles&#91;i&#93;.filename, thefiles&#91;i+1&#93;.filename&#41; > 0&#41;&#41;
		&#123;
			strcpy&#40;tempfilename, thefiles&#91;i&#93;.filename&#41;;
			strcpy&#40;temppath, thefiles&#91;i&#93;.path&#41;;
			tempflags = thefiles&#91;i&#93;.flags;
			strcpy&#40;thefiles&#91;i&#93;.filename, thefiles&#91;i+1&#93;.filename&#41;;
			strcpy&#40;thefiles&#91;i&#93;.path, thefiles&#91;i+1&#93;.path&#41;;
			thefiles&#91;i&#93;.flags = thefiles&#91;i+1&#93;.flags;
			strcpy&#40;thefiles&#91;i+1&#93;.filename, tempfilename&#41;;
			strcpy&#40;thefiles&#91;i+1&#93;.path, temppath&#41;;
			thefiles&#91;i+1&#93;.flags = tempflags;
			i = -1;
		&#125;
	&#125;
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.
Post Reply