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”
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)”
Step 3:
Drag “For Each” activity into the design panel and pass the above “filesList” variable to it.
Step 4:
Drag “Message Box” activity into the For Each activity and pass the “item” value into it.
Step 5:
Finally!!!
when we run it, we can see the file names of .zip extension being displayed.
Click here to download the Source Code…
Hope it has helped you…
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)â€
Hey GangaReddy, Thanks
Try this 🙂
Directory.GetFiles(folderPath,â€*.zip”,System.IO.SearchOption.AllDirectories).Union(Directory.GetFiles(folderPath,â€*.png”,System.IO.SearchOption.AllDirectories)).ToList