Yellow highlighted mark is a date “20230123” “2023\01\23” this is latest date
I want “main_20230123102454_data” to fetch this name
@Anil_G @Palaniyappan @Yoichi
Please try this
Directory.GetFiles("Folderpath","*.csv").OrderBy(function(x) DateTime.PraseExact(Path.GetFileNameWithOutExtension(x).Split("_"c)(1),"yyyyMMddHHmmss",System.Globalization.CultureInfo.InvariantCulture)).Last
If HH doesnt work try with hh
Cheers
If the date always is in the format yyyyMMdd, you can just use text sorting without converting it to datetime first.
lastestFile = Directory.GetFiles("C:\test").OrderByDescending(Function(x) System.Text.RegularExpressions.Regex.Match(x, "(?<=_)\d+").ToString).First
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.