I am new to Uipath.
I have many files of different extensions in a folder. I wanted to sort the files according to the date(ddmmyyyy) which the file names have and create a dynamic folder according to the year(yyyy) which the files name has and move the file to the particular folder.
If the file name has no date I wanted to create a dynamic folder with the current date and move that file to the respective folder.
You have to perform following steps to achieve this.
1-Read the parent directory where all files are present. It will return collection.
2-use for each loop for the collection then inside loop get file name as string.
3-Now create a string variable and get substring. like this str.Substring(str.Length -4)
It will give you year for example File= 1. abc_report_10102018 it will return 2018
4- Apply check if variable value that you have created at point no 3 is null or empty then that mean file doesn’t have date.
5- Use create folder activity to create folder.
6-Use move file activity to move the file to that specific folder.
The flow runs fine for all the files except .xlsx file
The problem I am facing is for the excel file the substring gives output the file as 018 instead of 2018.
Can you help me with this, please?
Hello I am still a bit confused, I am still a beginner myself, can I send you my workflow and just check it out for me please. I want to sort out annnual files, for instance, if the file is from the year 2019, then a 2019 document should be filed under a 2019 folder(that I would have to create within the workflow as well) I am not sure if I am making sense.
I wouldn’t solve this with Regex - the code turns really messy because the expression need to capture text after the second “_” and before the “.”. Also, some files need not be in this format.
The solution I have posted actually handles this task pretty well. Alternatively, you could use the following approach
Check if string has two “_” characters (else get year from current date)
Split string and check if text after second “_” has at least 8 characters (else get year from current date)
Get substring of the characters after the second “_” and check if it is a year (else get year from current date)
You see? This approach is quite messy too, but is still cleaner than the regex approach.