Get Latest File
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?
*Implementation using UiPath
Step 1:
Drag “Assign” activity into the designer panel and supply the “Folder Path” to it.
Example :
our_FolderPath = “C:\Users\Sanjit.Pal\Downloads”
Step 2:
Drag “Message Box” activity into the designer panel and supply the below-mentioned code to it.
String.Join(“”, Directory.GetFiles(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
Delete Multiple File
While automating business processes, we deal with a lot of files and might perform few activities on them like deleting, moving or renaming.
Here, for now, let’s see how to delete multiple files from a folder!!!
Step 1:
Drag “Assign” activity into the designer panel and supply the “Folder Path” to it.
Step 2:
Drag “If” activity to check if the folder contains any files.
Directory.GetFiles(DirectoryPath).Count > 0
Step 3:
Drag “Invoke Code” activity, supply the below-mentioned code to it to and pass the folder’s Path from which we have to delete the files.
Array.ForEach(Directory.GetFiles(DirectoryPath),Sub(x) File.Delete(x))
Step 4:
Now, execute the workflow to find the result
Get Specific Type of File
Step 1:
Drag “Assign” activity into the design panel and populate it with your folder path
example: “C:\Users\Sanjit.Pal\Downloads\New folder”
Step 2:
Drag “Assign” activity into the design panel and populate it with above-mentioned code
example: “Directory.GetFiles(FolderPath,”.zip”,System.IO.SearchOption.AllDirectories)”*
Hope You enjoyed this article.