How To Get Specific Type Of Files From A Folder – In UiPath

File management is inevitable in business processes automations.

We might want to copy, move or delete files based on few conditions…!!!

Let’s see how to get the specific type of files from a folder 🙂

_myList = Directory.GetFiles(_folderPath,”*.zip”,System.IO.SearchOption.AllDirectories)

Note:
1. _folderPath is the folder path where you have your files
2._myList is the variable containing your required files
3.Replace “*.zip” with your desired extension.


Example

Implementation using UiPath :

Let us implement a workflow which displays the names of particular files(.i.e .zip extension files) from a folder.

Step 1:
Drag “Assign” activity into the design panel and populate it with your folder path
example: “C:\MyFolder”

UiPath Get Particular Files from a folder 1.PNG

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

UiPath Get Particular Files from a folder 2.PNG

Step 3:
Drag “For Each” activity into the design panel and pass the above “filesList” variable to it.

UiPath Get Particular Files from a folder 3.PNG

Step 4:
Drag “Message Box” activity into the For Each activity and pass the “item” value into it.

UiPath Get Particular Files from a folder 4.PNG

Step 5:
Finally!!!
when we run it, we can see the file names of .zip extension being displayed.

UiPath Get Particular Files from a folder 5.PNG

Click here to download the Source Code…

Hope it has helped you…

 

 

 

Advertisements

Author: Sharath Raju

Founder@www.ExcelCult.com

2 thoughts

  1. Hi Sharath bro,
    Thanks for the good article.
    When we needed multiple files like (.png and .pdf) what might be the code
    is this valid?
    “Directory.GetFiles(folderPath,”*(.zip|.png)”,System.IO.SearchOption.AllDirectories)”

    1. Hey GangaReddy, Thanks

      Try this 🙂

      Directory.GetFiles(folderPath,”*.zip”,System.IO.SearchOption.AllDirectories).Union(Directory.GetFiles(folderPath,”*.png”,System.IO.SearchOption.AllDirectories)).ToList

Leave a Reply