我有一个名为 IncomingFiles
的文件夹。在该文件夹中,我有多个文件。仅包含 .xml 文件。
以下是 IncomingFiles
文件夹下具有不同时间戳的文件列表:
例如:
+-------------------+---------------------+---------------+
|Name | Date Modifided | Type |
+-------------------+---------------------+---------------+
| test4.xml | 23/6/2016 12:30 PM | XML Document |
| test3.xml | 23/6/2016 12:20 PM | XML Document |
| test2.xml | 23/6/2016 12:10 PM | XML Document |
| test1.xml | 23/6/2016 12:00 PM | XML Document |
+-------------------+---------------------+---------------+
我必须根据较早的时间获取文件。
例如:
First i have to fetch below file:
test1.xml
Second I have to fetch below file:
test2.xml
Third I have to fetch below file:
test3.xml
Fourth I have to fetch below file:
test4.xml
如何做到这一点。请帮我解决。
最佳答案
使用按 LastWriteTime
排序的 linq 和仅 .xml
文件:
DirectoryInfo dirInfo = new DirectoryInfo("IncomingFiles");
List<FileInfo> files = dirInfo.GetFiles()
.Where(f => f.Extension == ".xml")
.OrderBy(f => f.LastWriteTime)
.ToList();
关于c# - 如何使用 C# 首先从目录中获取旧文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37984971/