Vb.net 目录中的文件按文件名升序排序-每个

Vb.net 目录中的文件按文件名升序排序-每个,vb.net,.net-4.0,Vb.net,.net 4.0,如何更新我的代码,以便按照创建日期/时间的顺序处理所有文件 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(

如何更新我的代码,以便按照创建日期/时间的顺序处理所有文件

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
您可以将LINQ用于:


请注意,您也可以使用
GetFiles
而不是
EnumerateFiles
。后者可能更有效。

我已将代码改为“.EnumerateFiles(Path,SearchPattern)”。我很高兴它能工作。@Jim:几秒钟前我已经修复了它,这是您代码中的复制粘贴问题;)@吉姆:我是从实践中学到的。在我自己的代码中使用LINQ而不是循环,或者在Stackoverflow上回答LINQ问题;)以下是一些建议,但我无法确定这些书是否值得推荐:
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