开发者

Question about windows system sorting problem

how can I get the file sequence which is the same as windo开发者_开发问答ws 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??


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...


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜