I save the Last Run Date Time in sql server and retrieve the datetime value everytime for a new trigger.
I need to get the files from the source location only if the filename timestamp is greater than Last run date time.
LastRunDateTime = “20220313”
The file name will be as follows:
I need to compare only the date from Filename with LastRunDateTime, and only if the filename date is greater than LastRunDatetime. Then I have to Copy all those files to another location.
Any helps and leads are much appreciated.
Hope the below steps would help you resolve this
- Use a assign activity like this
arr_filepaths = Directory.GetFiles(“yourfolderpath”)
Where arr_filepaths is a variable of type array of strings
Let’s take like you have your last run Datetime in a string variable named strtime
Now use a FOR EACH activity and pass the above array variable as input and change the type argument as string
Inside the loop use a IF condition like this
Datetime.ParseExact(Split(Path.GetFileNameWithoutExtension(item.ToString), “_”)(1).ToString.Trim, “yyyyMMdd”, System.Globalization.CultureInfo.InvariantCulture) > Datetime.ParseExact(strtime.ToString.Trim “yyyyMMdd”, System.Globalization.CultureInfo.InvariantCulture)
If true it goes to then block where use a Move file activity and in source mention as item.ToString and in destination mention your folder path
You can load the records into an array variable with code.
Then you can do a search in your array variable, doing a split to get the date snippet and compare with the current date, following example code.
aryFile.Where(function(x) date.ParseExact(New FileInfo(x).Name.Split("_"c)(2).ToString, "yyyyMMdd", Nothing) >= Now.Date)
So for your project, I believe it would look like this.
aryFile.Where(function(x) date.ParseExact(New FileInfo(x).Name.Split("_"c)(2).ToString, "yyyyMMdd", Nothing) >= date.ParseExact(LastRunDateTime, "yyyyMMdd", Nothing))
you can try like this
Goto Imports-> and search for System.Globalization and System.Text.RegularExpressions
- For each file in folder
- If DateTime.ParseExact(“LastRunDate”,“yyyyMMdd”,CultureInfo.InvariantCulture) > DateTime.ParseExact(Regex.Match(Path.GetFileNameWithoutExtension(CurrentFile.ToString),"(?<=_)\d+(?=_)").ToString,“yyyyMMdd”,CultureInfo.InvariantCulture)
- True-> Copy file Source will be CurrentFile.Tostring
Here is the sample SS and flow
Sequence.xaml (8.8 KB)
Hope this Helps!!
Hi @Palaniyappan ,Thank you for replying to my post.
I get the following error in the IF
Can you please help me with the error.
Hi @Sudharsan_Ka , Thanks for replying to my post.
The source folder has lots of other files, Hence I’m only filtering for specific filename and then I have to only copy the files which are greater than lastrundate from source folder to inputFolder.
For each file in Folder does not work for my usecase.
Can you suggest me other solution.
Have you Checked the flow\Skeleton which i sent @Sirimalla_Karthik_Chandra
Because I have included the condition as well
Try that and let me know if you need further assistance
I opened the xaml file shared by you, However there was a package issue.
Simply upgrade your all packages or check the package and compare the necessary packages with the dependencies here
I not allowed to use Balareva packages in my project. Can you please share me the xaml file with only required packages if possible.
That’s used in my project you can check only the dependencies you want
Upgrade your Uipath.System.Activities package
No luck, I had updated all the packages. Still the same issue.
So let’s create a new workflow
- Search for For each file in folder and drag them in
- If and give the condition I mentioned above
DateTime.ParseExact(LastRunDate,“yyyyMMdd”,CultureInfo.InvariantCulture) > DateTime.ParseExact(Regex.Match(Path.GetFileNameWithoutExtension(CurrentFile.ToString),"(?<=)\d+(?=)").ToString,“yyyyMMdd”,CultureInfo.InvariantCulture)
Where LastRunDate = Your mentioned date
@Sudharsan_Ka , I have found the solution myself. Thank you so much for your effort.
my solution is as follows:
Taking assign Getfiles=directory.getfiles(FolderPath,“Auth_released*.txt”)
second assign lastdate = “20220313”
taking for each and assigning Getfiles as input
Inside Foreach dragging IF Activity and passing the below expression
So this way my issue got resolved.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.