How To Delete Multiple Files – In UiPath

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

Array.ForEach(Directory.GetFiles(our_DirectoryPath),Sub(x) File.Delete(x))

Note:
Replace our_DirectoryPath with your desired folder path

Example

Implementation using UiPath :

Let us implement a project to delete multiple files from a given folder 🙂

Step 1:
Drag “Assign” activity into the designer panel and supply the “Folder Path” to it.

UiPath Delete Multiple files from a folder 1.png

Step 2:
Drag “If” activity to check if the folder contains any files.

Directory.GetFiles(DirectoryPath).Count > 0

UiPath Delete Multiple files from a folder 2.PNG

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

UiPath Delete Multiple files from a folder 3UiPath Delete Multiple files from a folder 4

Step 4:
Now, execute the workflow to find the result 🙂

Click here to download the Source Code…

Hope it has helped you…

Leave a Reply

%d bloggers like this: