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…

 

 

 

Advertisements

Author: Sharath Raju

Founder@www.ExcelCult.com

Leave a Reply