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

查看:14
本文介绍了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[] 文件 =info.GetFiles().OrderBy(p => p.CreationTime).ToArray();foreach(文件中的文件信息文件){//做点什么... }

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

这里是按创建时间获取目录中文件的示例代码.

here is the sample code for get files in directory by creation time.

同样可以按大小获取文件.

You can get files by size same way.

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

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