mr_Fajar_28
(Muhamad Rizky Fajar)
August 12, 2022, 2:45am
1
Hi! i’m trying to get file’s name sorted by name ascending. in this case i have files with name :
RPA_020822_1.txt
RPA_020822_5.txt
RPA_010922_1.txt
RPA_020822_11.txt
the format name file is RPA_DDMMYY_x.txt (x is sequence). i’ve already sorting by datetime but actual result was :
RPA_010922_1.txt
RPA_020822_1.txt
RPA_020822_11.txt
RPA_020822_5.txt
My Expected result was :
RPA_010922_1.txt
RPA_020822_1.txt
RPA_020822_5.txt
RPA_020822_11.txt
by the way, i using this expresion inside a for each loop
Directory.Getfiles(mypath, “RPA*.txt”).OrderBy(Function(x) DateTime.ParseExact(system.text.RegularExpressions.Regex.Match(Path.GetFileNameWithoutExtension(x), "\d{6}\d{1,}“).Value.ToString.Split(” "c)First, “ddMMyy”, System.Globalization.CultureInfo.InvarianCulture))
Yoichi
(Yoichi)
August 12, 2022, 3:04am
2
Hi,
Can you try the following sample?
files = Directory.Getfiles(mypath, "RPA*.txt").OrderByDescending(Function(x) DateTime.ParseExact(System.Text.RegularExpressions.Regex.Match(Path.GetFileNameWithoutExtension(x), "\d{6}(?=_\d+$)").Value, "ddMMyy", System.Globalization.CultureInfo.InvariantCulture)).ThenBy(Function(f) Int32.Parse(System.Text.RegularExpressions.Regex.Match(Path.GetFileNameWithoutExtension(f), "\d+$").Value)).ToArray
Sample20220812-5.zip (3.2 KB)
Regards,
mr_Fajar_28
(Muhamad Rizky Fajar)
August 12, 2022, 4:45am
3
it work but i change it in the text of “\d+$”, because regex value of it make result “” and it can’t be convert to integer
system
(system)
Closed
August 15, 2022, 4:46am
4
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.