Want the robot to pick a folder and collect all the files like a very obedient digital raccoon? Use the Select Folder activity to get a path and then use System IO methods to pull file names. This approach works for simple jobs and scales better when you choose the enumerable pattern for huge directories.
Drag the Select Folder activity from the Activities panel and assign its output to a String variable named folderPath
. No need for detective work or hard coded paths. Let the user point at the folder and call it a day.
Use an Assign activity to call the System IO methods in VB.NET. For small to medium folders the array method is fine. For large repositories prefer the enumerable method to avoid memory surprises.
files = Directory.GetFiles(folderPath, "*.*", SearchOption.AllDirectories)
filesEnumerable = Directory.EnumerateFiles(folderPath, "*.*", SearchOption.AllDirectories)
Use SearchOption.AllDirectories
to recurse into subfolders or SearchOption.TopDirectoryOnly
for single level scans. Swap the search pattern to something like "*.pdf"
to limit results.
Use a For Each activity. Set the TypeArgument to String
and iterate over the array or enumerable. Typical actions include reading file content moving files or logging names for later processing.
files
or filesEnumerable
String
You can filter by extension using the search pattern in the GetFiles call or by applying LINQ after you have the list. Example without drama:
pdfOnly = files.Where(Function(f) Path.GetExtension(f).Equals(".pdf", StringComparison.OrdinalIgnoreCase)).ToArray()
LINQ gives you fancy filtering without adding 100 lines of procedural code.
Store file paths in a DataTable log them or pass them to downstream workflows. Real life throws permission errors and locked files at you. Wrap file operations in Try Catch activities and handle exceptions gracefully. If performance is a worry prefer Directory.EnumerateFiles
so you stream paths instead of slamming memory with everything at once.
"*.xlsx"
or use LINQ for complex rulesThere you go. A simple, reliable way to let users pick a folder and have UiPath gather every file for processing. It is polite to the system and efficient when you choose the right method. Now go automate something that used to make you cry.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.