Delete multiple files in a folder using UiPath

While automating a business process, a lot of files or folders are involved in the process of automation.

So, let’s see how we can delete multiple files in a folder.

This is one of the important task while designing workflows for automation.

There are two ways to delete files from a folder.

We will see how we can achieve that using individual ways.

First Method:

Step1: Drag and Drop an Assign Activity into the designer panel and provide the folder path where we want to delete the files as shown below.

delete files in a folder

Step2: Drag and Drop a For Each Activity and also a Delete Activity inside the for each as shown below:

delete files in a folder

The input for the Delete Activity is the file path i.e., item which provides individual file paths to delete activity to delete every file from the folder.

This is one way of doing it and let’s see the other way.

Second Method:

The second method is based on using invoke code activity.

Step1: Drag and Drop an Assign Activity into the designer panel and provide the folder path where we want to delete the files as shown below.

delete files in a folder

Step2: Drag and drop an invoke code activity and use the below syntax inside the code.

Array.ForEach(Directory.GetFiles(folderPath),Sub(x) File.Delete(x))
delete files in a folder

Firstly, click on edit code and enter the above syntax inside the invoke code.

After doing that click on edit argument and create an argument that contains the folder path that we took in step1.

This is how you can achieve this task using two different methods.

Happy Learning!

Like this post then let your friends know about this-:

Leave a Reply

Your email address will not be published. Required fields are marked *