uipath technical infomation for everyone

Get the latest file in a folder


To get the latest files, use the .Net System.IO.Directory class GetFiles method.

 

Overall flow

 

Procedure

Place an

1 Assaing activity.

Stores the value of the folder to search for files. Here it is strFolder (String type).

 

strFolder = System.IO.Directory.GetCurrentDirectory ()
* System.IO.Directory.GetCurrentDirectory () gets the path of the folder running Xaml. Please change this part according to your environment.

 
Place an

2 Assaing activity.

Stores the return value of the GetFiles method.

 

Directory.GetFiles (strFolder, “sample *”, SearchOption.TopDirectoryOnly) .OrderByDescending (Function (x) New FileInfo (x) .LastWriteTime) .Take (1)

 

* The folder specified by “1.” in strFolder is specified, and “sample *” is the file name. Intended for files whose file name matches “sample”.

 

 

If “LastWriteTime” is set to “CreationTime”, files can be acquired with the latest creation date.

 

fileList specifies the IEnurable type.

 
Place an

3 For each activity.

Since one latest file is acquired, if there is a file, it enters once in the For each loop. If there is no file, it does not enter the loop.

 

4 For each activity property.

TypeArgument specifies String type.

 

The absolute path of the file name is displayed in item.ToString.