Hi I have project, where I need to look through multiple folders located under different locations and if files are there with date created within last month, then copy those files to a new folder.
Example:
Folder A - Located at \epic-nas.et1157.epichosted.com\xfr\nonprd\fromODB\Claims\PBClaims\UiPathTestingThree
Folder B - Located at \sbonas01\DRM_REQS\MedAssets\BusinessAnalysis\Automated Reports Epic\WEEKLYEPICFOLLOWUPWQREPORTS
I am using the For Each Activity and in the List of Items I am using Directory.GetFiles(âMyLocationâ) and then using the If Condition to Look at New FileInfo(CurrentRemitFiles).LastWriteTime >= Today.Date.AddMonths(-1) - Look at last month
And then Copying those files and moving to new location.
Only issue is how can I reference Multiple directories as I can only reference For Each?
Put the directories into an array of a For Each. Then put your existing For Each inside that For Each. Make sure to name the âitem nameâ variable differently for each For Each, so they donât interfere with each other. So now youâre looping through an array of paths, and inside that loop youâre looping through the files in the folder.
However, usually what I would do is put the folders into a config file as a comma delimited list, and then use Split to turn it into an array in the For Each. Or maybe youâre getting the list of folders from elsewhere in the processâŚeither way youâre getting the list of folders just pass them as an array to the For Each.
By the way, you might want to look at using For Each File in Folder for your interior loop. Just a version of For Each thatâs more specific to looping through files than the regular For Each.
So youâd haveâŚ
For Each (loop through array of folders, set its variable to currentFolder)
â For Each File in Folder (pass currentFolder to it, and set its variable to currentFile)
â Here you do your file date etc checks against currentFile and file move
Because youâre using For Each File in Folder, currentFile will be a FileInfo object that will give you direct access to various properties of the file (just type currentFile. and the menu will appear showing you all the properties).
Can you share what you mean by this, I am struggling here as I am not a coder. I tried looking online what you are referring to but having hard time programming this. If you can share how you would code it that would be much appreciated.
For Each through an array of folders. I have hard-coded the folders array but you can create arrays many different ways - just depends on your process.
Stupid question but âFor Each CurrentFolderâ is this same activity as in âFor Each Folder in Folderâ? I cannot seem to located the For Each CurrentFolder activity and my selection option is bit different than what your screenshot shows.
If same, when I type in this {â\epic-nas.et1157.epichosted.com\xfr\nonprd\fromODB\Claims\PBClaims\UiPathTesting",â\epic-nas.et1157.epichosted.com\xfr\nonprd\fromODB\Claims\PBClaims\UiPathTestingThree"} as my folder paths, I am getting error stating BC3011 Value of type âString()â cannot be converted to âString.â The selected value is incompatible with the property type.
Also, under For Each File in Folder I am getting error for the âIn Folderâ line, it is stating BC30311: Value of type âDirectoryInfoâ cannot be converted to âStringâ. The selected value is incompatible with the property type.
No. Itâs a regular For Each and you name the variable CurrentFolder instead of currentText. If you have a For Each activity inside another For Each activity and they both have the same variable name, theyâll step on each other and it wonât work right.