Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# How do I use Directory.GetFiles() to get files that have the same order as in Windows explorer?

Tags:

c#

directory

Is is possible to get files that is ordered same as in Windows Explorer

I know "natural sort", but it's not what I need, I need to get the file list ordered by the same attribute in Windows Explorer, for example:

If I ordered a directory by the attribute "create date", then I will get a file list as below:

name                    create date    file size
1.txt                   2012/1/1        125Kb
2.tab                   2012/3/2        15Kb
3.bmp                   2013/5/5        26Kb

If my windows explorer order file list with the attribute "file size", the the file list would be:

name                     create date    file size
2.tab                    2012/3/2        15Kb
3.bmp                    2013/5/5        26Kb
1.txt                    2012/1/1        125Kb

Could anyone help?

like image 965
Shawn Lee Avatar asked Aug 03 '12 03:08

Shawn Lee


Video Answer


1 Answers

I think this is going to be a lot more complex than you expect. Folder settings are stored in the registry in two places:

HKCU\Software\Microsoft\Windows\Shell\BagMRU
HKCU\Software\Microsoft\Windows\Shell\Bags

The first path contains a structure which reflects the structure of the file system, and the second path contains details about those items, including a REG_BINARY value called "Sort" which records the sort order used for that folder.

See Willi Balenthin's website for details on the structure, including sample code (in Python)

like image 105
Simon MᶜKenzie Avatar answered Sep 21 '22 01:09

Simon MᶜKenzie