If round 1 , I want to get file that lowest (read date after _ ) Ex AAA_20211010.xlsx
round2 , get file = BAS_20211010.xlsx
round3, get file = AAA_20211011.xlsx
round4, get file = AAA_20211012.xlsx
then you can compare and fetch the oldest date and the file corresponding to it
for this, you may use a function on datatable or an IF condition
store the first item in the variable, dateOldest
then as the loop iterates, just compare it the current item’s date is older than dateOldest. You can use normal < to compare dates.
after the loop ends you’ll have the oldest date
and you can open the file with that date
I feel like when file is created with datetime included in its filename it would have been added or created or moved to the folder at specific time that is considered as CreationTime
So if we can sort with the CreationTime it would probably give the order of files on lowest date as well
Use a assign activity like this
arr_filepath = Directory.GetFiles(“yourfolderpath”,*.xlsx”).OrderBy(Function(a) New Fileinfo(a).CreationTime).ToArray()
@Maria99
we do understand that you are looking for are ordering taking 2 criterias into account
first token till the underscore
date information within filename
Ensure following:
Flow:
(From fi In New DirectoryInfo("C:\_demo\Subfolder").GetFiles()
Let prfx = Regex.Match(fi.Name, "^.*(?=_)").toString
Let sd = Regex.Match(fi.Name, "\d{8}").toString
Let dtp = DateTime.ParseExact(sd,"yyyyMMdd", CultureInfo.InvariantCulture)
Order By dtp,prfx
Select f=fi.FullName).toarray
Line1: readin all files for looping
Line2: Extract the prefix part till _
Line3: Extract the date part
Line4: parse the date string into a Datetime
Line5: Order on prefixpart, date
Line6: Extract the FullFilePath
return a String Array
We are working with DirectoryInfo / FileInfo classes as we do benefit that different information are available with less code (e.g. FileName only)