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…

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: