Looking for a way to move the most recent file in a folder using StudioX. I have tried the following using the string builder however it doesn’t seem to work.
String.Join("",Directory.GetFiles(“FolderPath”,“FileType/FIleNameSequence”,SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1) )
Hi @shanalie.evans ,
How to get latest file in folder using uipath
Get the latest file in a folder
After getting the latest files using the methods mentioned in the above posts you can use the Move File activity for moving the most recent file.
Hope this helps
Thank you so much for the quick response!
To clarify, I was using the Move File activity and entering the string builder into the “From” field. Is there another action or card I should be using in between?
You can also use Get Last Modified activity by installing uipathteam.file.activities package.
Please find the attached workflow for moving the last modified file from the folder.
MoveLatestFile.zip (2.5 KB)
Darn! When I search under “All Packages” I cant seem to find that one. I tried copying and searching for key words. I will ask my organization why that might be. However in the meantime is there a reason why you can think the string builder under move file wouldn’t work?
you don’t need to install any packages in studiox. just create a new project and you will have by default all needed packages for all actions you need in studiox
Thank you so much for your help! So I can see that Studio is taking the name for each file in my folder, however once I write the current file and name I am not quite sure what to do next since its writing the name for every file within that folder. When I add the move file card it errors out.
There is nothing wrong with your code. But your code will only work if the variable for the Folder Path is inserted correctly:
For example, if you named/assigned your Folder Variable = FileFolder
Then the command should be
String.Join("", Directory.GetFiles(FileFolder,"*.pdf",SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1))
See attached image please.
Thanks for the Update , I was tried this method it’s working , but when I add add to queue inside the body I was getting the error like this …
Can you help me to resolve this issue. instead of Directory.GetFiles(“C:\Users\Test\Downloads”)" I need to use config directory values.