如何更新我的代码,以便按创建的日期/时间顺序处理所有文件?
Private Sub StartupFindExistingFiles(Path As String, SearchPattern As String)
Dim fileEntries As String() = Directory.GetFiles(Path, SearchPattern)
For Each fileName As String In fileEntries
PrintJOBFile(fileName)
Next
End Sub
答案 0 :(得分:1)
您可以将LINQ与File.GetCreationTime
:
Dim orderedByCreation = From file In Directory.EnumerateFiles(Path, SearchPattern)
Let createdAt = System.IO.File.GetCreationTime(file)
Order By createdAt Ascending
Select file
For Each filePath As String In orderedByCreation
PrintJOBFile(filePath)
Next
请注意,您也可以使用GetFiles
代替EnumerateFiles
。后者可以更有效率。