Hello ,
I need to sort the files in a folder based on file name which has datetime stamp.
For example:
I have 4 text files in a folder named
Cart_EY_23032022
2.Cart_EY_24032022
3.Cart_EY_01012022
4.Cart_EY_15022022
I need to sort all the above files based on the datetime stamp which is in filename.
Note: I cannot use file creation date or date modified to sort the files.
Any leads are appreciated.
Gokul001
(Gokul Balaji)
March 3, 2022, 6:12am
2
Hi @Sirimalla_Karthik_Chandra
I’m not sure but try this
Use For Each File in Folder Activity
Filter by → “*.txt”
Order by → Name ascending first
Look into the screenshot
Regards
Gokul
1 Like
jack.chan
(Jack Chan)
March 3, 2022, 6:18am
4
you can use
listOfFiles.OrderBy(function(x) System.Text.RegularExpressions.Regex.Match(x, "([\d]{8})").Groups(1).value).ToList
this will sort it by timestamp only so the text etc wont matter
my sequence for reference:
test.xaml (9.4 KB)
1 Like
Yoichi
(Yoichi)
March 3, 2022, 6:21am
5
Hi,
Can you try the following expression?
files = System.IO.Directory.GetFiles(yourFolder).OrderBy(Function(f) DateTime.ParseExact(System.Text.RegularExpressions.Regex.Match(System.IO.Path.GetFileNameWithoutExtension(f),"\d{8}$").Value,"ddMMyyyy",System.Globalization.CultureInfo.InvariantCulture)).ToArray
Regards,
1 Like
Hi @Yoichi , Thanks a lot man. The expression given by you is working.
1 Like
Could you Please help me to sort if the file also have a timestamp along with date.
For example: if the file name is
1.Cart_EY_03032022_1501
2.Cart_EY_03032022_1530
3.Cart_EY_03032022_1640
Yoichi
(Yoichi)
March 3, 2022, 9:48am
8
Hi,
The following will work. Can you try?
System.IO.Directory.GetFiles(yourFolder).OrderBy(Function(f) DateTime.ParseExact(System.Text.RegularExpressions.Regex.Match(System.IO.Path.GetFileNameWithoutExtension(f),"\d{8}_\d{4}$").Value,"ddMMyyyy_HHmm",System.Globalization.CultureInfo.InvariantCulture)).ToArray
Regards,
1 Like
Thank you so much for helping me out. @Yoichi
1 Like
system
(system)
Closed
March 6, 2022, 9:52am
10
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.