Breaking News

Get files from a folder with UiPath

In this exercise, I will show you how to build an automation in UiPath which gets all the files from a specific folder and write their names into a TXT file.

New Process

First, create a new process. Enter a suggestive Name like 01GetFilesFromFolder. Next, enter a Description for the automation. In my case, I went with “The automation gets all the files from a specific folder”.

Automation flow

Now you have to decide if you are going to use a Sequence or a FlowChart. In this simple example, the flow is linear so I will select the Sequence flow. Drag and drop the Sequence from the left side panel called Activities. Rename the sequence to “Main Sequence”. As a best practice, you should use suggestive names for all the activities.

UiPath Studio

Select Folder

After I decided to go with the Sequence activity I have to design the linear flow. As I mentioned in the first paragraph I want to get all files from a folder. So the first activity inside the sequence is Select Folder activity. Use the search functionality provided by the Activities left side panel. Drag and drop it inside the sequence.

Configure the properties of the newly added activity. Press CTRL+K to create a new variable where you are going to save the path of the folder.

I have decided to go with sSelectedFolder. It’s String type variable. Make sure you check the type and the scope of the variable.

Assign

.Net provides a method which allows you to return all the files from a specific folder. The method is called Directory.GetFiles. I will use the Assign activity to save the output of this method. The output is an array of strings.

Tip for the Assign activity

The Assign activity accepts IF statement. You can assign a value to a variable using if condition. For example you want to assign TRUE or FALSE to a variable called isPositive. On the left input(TO) enter the name of the variable and on the right (Value) enter the following statement.

if(number > 0, true, false)

*** if(condition, when condition is true, when condition is false)

Nested IFs:

if(color = “green”,”The selected color is GREEN”, if(color = “red”,”The selected color is RED”,”The selected color is neither GREEN nor RED”))

For Each

I would like to iterate through each item of the array and add a new line to separate them. In the end, I want to save everything in a string variable. Drag and drop a For Each activity after Assign activity. For the new line use System.Environment.NewLine

Write Line

To display the content of the variable use Write Line activity. The content is displayed on the Output panel of the studio.

Open Application

To open an application drag and drop the Open Application activity. To configure the activity you need to have the specific application opened. So go to Windows and type notepad and open the application.

Tip: don’t select notepad++ for now. For this example let’s use the default notepad.

Select the selector Indicate window on screen. Go to your already opened notepad and select it.

Make sure to position your mouse on top of the application. You must see how the selector selects the entire application. After the configuration the activity has to look like this.

Type Into

Inside Do block, drag and drop the Type Into activity. Set the text as sFile. The content of this variable will be typed into the notepad.

The result

The entire automation: Select Folder > Assign > For Each > Open Application and Type Into

Download the solution

I’ve attached the UiPath solution. You can download it from the button below.

About Valeriu B

RPA Developer (UiPath certified)

2 comments

  1. wrong file to download

    • You can download the correct automation now. I replaced the zip file with the correct one. Thanks 🙂 !!!

Leave a Reply

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