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
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