Hi Folks,
I recently asked a question on how to find files matching a given filespec. CommonTater helpfully pointed me to the API functions FindFirstFile, FindNextFile and FindClose, which answered the question as asked.
However, as noted in the API documentation, "The order in which the search returns the files, such as alphabetical order, is not guaranteed, and is dependent on the file system. You cannot depend on any specific ordering behavior. If the data must be sorted, you must do the ordering yourself after obtaining all the results." Under NTFS, the files appear to be alphabetical, but as noted, this is not gauranteed.
My follow up questions is on sorting (- which seems to be a fairly common question on Google!). There does not appear to be any other native functions to sort the files returned?
I realise that I can read the returned filenames into an array and sort them in C (or try to!), but it would appear to be far easier to do a dos shell command and parse the output of "dir /o:n" and store the sorted list directly. I'm interested in whether there is much benefit in writing a sort algothim in C when I can use the features of the OS?
I guess that there is probably a speed penalty of doing it through a shell command, but for what are likely to be a few files (<100) then this is probably not significant?
regards
Dave