When we download a file from the browser or some application, we might need to have the downloaded file to proceed further.
So, how to get the latest file from a folder?
String.Join(“”, Directory.GetFiles(our_FolderPath,”*”,SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1) )
Note:
1.Replace our_FolderPath with your desired folder path
2.Replace “*” with your required file format “*.xlxs”,”*.pdf”…
Example
Implementation using UiPath :
Let us implement a project to get the latest file from a folder 🙂
Step 1:
Drag “Assign” activity into the designer panel and supply the “Folder Path” to it.
Example :
our_FolderPath = “C:\Users\sharathm\Documents\UiPath\HowToGetTheLatestFileFromAFolder_Example\SampleFolder”
Step 2:
Drag “Message Box” activity into the designer panel and supply the below-mentioned code to it.
String.Join(“”, Directory.GetFiles(our_FolderPath,”*”,SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1) )
Step 3:
Finally, run the workflow to display the path of the latest file 🙂
Click here to download the Source Code…
Hope it has helped you…
Yes, It helped a lot!! Thanks
Thanks Manish😊
That helped a lot. Thank you so much 🙂
Happy to hear that, thank you Sumana?