tags:

views:

61

answers:

2

Hi all, how can I get the file sequence which is the same as windows file system? Because there are so many file system sorting items: name, size, last modified date time, tag(win 7), rating(win 7), so if I using CFileFind API to simulate the sorting behavior as windows file system is quite difficult. So how can I get the files whose sequence is the same as windows file system??

A: 

I'm not sure what CFindFile does, but FindFirstFile and friends returns files in the order they exist in the NTFS directory.

I'm not sure why that would be the most desirable, though, it's not exactly "intuitive" by anyone's definition...

Dean Harding
CFindFile method is similar to FindFirstFile, both of them are sorted according to alphabetical. Somebody suggests me to use IShellFolder API, is anybody familiar with IShellFolder method?
Oh, I didn't understand your question... I thought you wanted files sorted in the file system order, not in the order that explorer uses. Explorer uses *approximately* the same order as StrCmpLogicalW, so you can probably use that to sort the filenames.
Dean Harding
Emm, I want to retrieve the file sequence the same as explorer, not file system order. But the file sequence in explorer is designed by user in file size, last modified date time, etc, and there are many sort criterion in explorer, so I can't simulate the explore file sorting. So it's not enough to sort file as StrCmpLogicalW.
A: 

Raymond Chen did a pretty detailed article on "Why do NTFS and Explorer disagree on filename sorting?"

However, note that FindFirstFile() and its relatives don't actually sort the results - it's just giving the files back to you in whatever order the filesystem hands them up. NTFS has an ordering for its own purposes (and I'm not sure that that ordering is specified - that it appears ordered to you is probably just a happy coincidence). FAT file systems and network filesystems will have their own ordering (or no ordering - the files might just be in the directory in whatever order they happened to be created - I think FAT systems are like that).

If you need a particular order for files returned by FindFirstFile() and friends, you'll need to do that sorting yourself.

From the FindFirstFile() docs: "FindFirstFile does no sorting of the search results. For additional information, see FindNextFile."

And from the docs for FindNextFile(): "The order in which the search returns the files, such as alphabetical order, is not guaranteed, and is dependent on the file system. If the data must be sorted, the application must do the ordering after obtaining all the results."

CFileFind() makes no promises about the order of the filenames returned - I'd be astonished if it did any sorting either (since it would have to get all possible files from the destination directory before returning the first one to be able to pull it off).

Michael Burr
Emm, I want to retrieve the file sequence the same as explorer, but the file sequence in explorer is designed by user in file size, last modified date time, etc, and there are many sort criterion in explorer, so I can't simulate the explore file sorting. So is there any method to get the file sequence as explore?