How To Get The Latest File From A Folder – In UiPath

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”

Get The Latest File From A Folder 1

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) )

Get The Latest File From A Folder 2.png

Step 3:
Finally, run the workflow to display the path of the latest file 🙂

Get The Latest File From A Folder 3.PNG

Click here to download the Source Code…

Hope it has helped you…

4 thoughts on “How To Get The Latest File From A Folder – In UiPath

  1. Manish

    Yes, It helped a lot!! Thanks

    1. Thanks Manish😊

  2. Mv Sumana

    That helped a lot. Thank you so much 🙂

    1. Happy to hear that, thank you Sumana?

Leave a Reply

%d bloggers like this: