C#如何使用Directory.GetFiles()来获取与Windows资源管理器中的顺序相同的文件? [英] C# How do I use Directory.GetFiles() to get files that have the same order as in Windows explorer?

查看:451
本文介绍了C#如何使用Directory.GetFiles()来获取与Windows资源管理器中的顺序相同的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以获得与Windows资源管理器相同的文件

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

我知道自然排序,但这不是我需要的,我需要得到在Windows资源管理器中由相同属性排序的文件列表,例如:

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

如果我的Windows资源管理器使用属性文件大小命令文件列表,文件列表将是:

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

有人可以帮忙吗?

推荐答案


使用System.Linq;

using System.Linq;

DirectoryInfo info = new DirectoryInfo ( ); FileInfo [] files =
info.GetFiles()。OrderBy(p => p.CreationTime).ToArray(); foreach
(文件中的FileInfo文件){
// DO Something ...}

DirectoryInfo info = new DirectoryInfo(""); FileInfo[] files = info.GetFiles().OrderBy(p => p.CreationTime).ToArray(); foreach (FileInfo file in files) { // DO Something... }

这里是

您可以通过大小相同的方式获取文件。

You can get files by size same way.

这篇关于C#如何使用Directory.GetFiles()来获取与Windows资源管理器中的顺序相同的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆