Sorting directory files and getting the highest file name

前端 未结 3 1711
既然无缘
既然无缘 2021-01-18 02:39

I have a directory with 40 files with names from 0 to 39 (for example), I am trying to get the file with the largest number in its name (which means I need to get \"39\") I

3条回答
  •  暖寄归人
    2021-01-18 03:17

    This is VB.NET to retrieve the highest numbered name. Changing the OrderByDescending key to x.LastWriteTime gets the newest file.

        Dim OldName As String = String.Empty
        Dim DI As New IO.DirectoryInfo("C:\")
        For Each FI As IO.FileInfo In DI.GetFiles("*.*").OrderByDescending(Function(x) x.Name)
            OldName = FI.FullName
            Exit For
        Next
    

提交回复
热议问题