How to use UiPath Select Folder to get all files |Video upload date:  · Duration: PT4M50S  · Language: EN

Quick UiPath guide to select a folder and retrieve all files from a directory using Directory.GetFiles and a For Each loop

Quick overview

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.

Step 1 Pick the folder

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.

Step 2 Get the files

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.

Step 3 Loop and process

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.

Example For Each setup

  • For Each item in files or filesEnumerable
  • TypeArgument set to String
  • Inside the loop do Read Text File Move File or custom processing activities

Filtering and LINQ fun

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.

Save results and handle errors

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.

Tips and caveats

  • Use EnumerateFiles for very large folders to reduce memory use
  • Set the For Each type argument to String or you will be sad and confused
  • Filter with search patterns like "*.xlsx" or use LINQ for complex rules
  • Catch UnauthorizedAccessException and IO exceptions so your robot does not die dramatically

There 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.