Hi everybody. I know how retrieve a list of files with the help of FindFirstFile and FindNextFile. (theoreticaly) But I don't know how to sort them alphabeticaly by there filename. Does one of you have got an idea how this can be done? I hope you can halp me :) sign CyBerian
Posted on 2001-03-10 19:00:00 by CyBerian
Yes, there is a way,I have not wrote one yet, but I can if it is needed, I was going to write one later on next month, anyway what you need is a simple bubble sort algo. or you can cheat, if your program is using a listbox anyway you can make sure it has the SBS_SORT when you create the list box, then as you send each file to the list box, the list box will sort them, you can then get them out in the order that they have been sorted. But that is cheating. So just let me know if you would like a bubble sort type Algo. and I will write it and e-mail it to you. otherwise I was going to do this next month, as I need it in my ZIP program also.
Posted on 2001-03-10 19:59:00 by Zcoder
If you could send me such an algorithm it would be very nice, because i am some kind of new to asm. I learn more each new day, but I am not sure how to create a sort algorithm. thx. sign CyBerian
Posted on 2001-03-11 05:50:00 by CyBerian
Here is a bubble sort:

; by Andrew Howe
; edi = pointer to some DWORDS
; ecx = Count of DWORDS
	lea	ebx,
	mov	eax,
	sub	ebx,4
	cmp	eax,
	jle	notyet
	xchg	eax,
	cmp	ebx,edi
	jnz	cmploop
	loop	outerloop
It's not a big ordeal to change this a string comparison. Instead of comparing the DWORDS in the inner loop, compare the strings pointed to by those DWORDS. This way you don't have to move the string data around - just the pointers to the strings. Hope this helps, bitRAKE
Posted on 2001-03-11 10:46:00 by bitRAKE
CyBerian, I need to know a few things about how you have your file names arranged, like are they all in a block of memory, are they all NULL terminated? do they contain the paths also? or are they just the file names? all this is important to the algo. another is is there a little more room in the memory area you have them stored. All of this is important cuz the bubble sort Algo. swaps the filename positions and with the way windows has long file names, each file could be longer the the other, This means you will have to have more room in the memory block to be able to adjust them around. or another way which is not a good way cuz it wastes memory while your sorting. is to Allocate another block and after the sorting is done you can delete the other block, I just need a little more into, cuz if I write one one way, it might not fit your app. the way you are handleing the files now.
Posted on 2001-03-12 15:55:00 by Zcoder
Zcoder, I would be interested in looking at your bubble sort code when you get it done, I wrote one, but I'm not satisfied with it. Ewayne
Posted on 2001-03-12 23:55:00 by Ewayne
k At the moment I read all the files(only the filenames,no directory) into a memory block. EveryFile String is NullTerminated HTH. sign CyBerian
Posted on 2001-03-13 06:26:00 by CyBerian
Buble sorting algorythm is pretty slow even using assembly ... I know some sorting algorythmn which are much more powerful .... such as the Fast Sorting one's ... it's in C++ but I'll try to translate it ... and I'll repost it !
Posted on 2001-03-13 09:39:00 by Newbie
The "classic" bubble sort compares and exchanges adjacent entries. The above sort is more of a classic "select and exchange" sort, where you're looking for a maxima (or minima) for a sublist on each pass.
Posted on 2001-03-13 14:16:00 by tank