If your automation needs to deal with files then Directory.GetFiles is the polite way to ask the folder what it is hiding. It returns a String array of full paths that you can loop over with a For Each activity and then read move or otherwise boss around. This guide gives clean steps examples and a few sarcastic remarks to keep you awake while you automate.
Use a String variable named folderPath to store an absolute location. Absolute paths save you from the thrilling experience of broken robots that blame relative paths for their life choices.
folderPath = "C\\Temp\\Reports"
files = Directory.GetFiles(folderPath)
This returns a String array with full file paths. If you do nothing else the order is not guaranteed so plan accordingly if order matters.
pdfFiles = Directory.GetFiles(folderPath, "*.pdf")
allFiles = Directory.GetFiles(folderPath, "*.*")
Patterns reduce wasted processing and keep the robot focused on the files you actually care about.
Set the For Each activity type argument to String and iterate the array returned by Directory.GetFiles. The loop variable contains the full path so you can feed it directly into Read Text File Move File or other activities.
For Each filePath As String In files
' Use Read Text File Move File or other activities here
Next
Wrap your file operations in a Try Catch activity. Catch IO exceptions and log a friendly message instead of letting the whole job explode. Robots appreciate graceful failure as much as humans do.
Try
' File operations here
Catch ex As System.IO.IOException
' Log the issue continue or retry as needed
End Try
Directory.GetFiles does not promise ordering. If you need a predictable sequence use LINQ to sort by full path file name or modify criteria to suit your workflow.
sorted = Directory.GetFiles(folderPath).OrderBy(Function(f) f).ToArray()
sortedByName = Directory.GetFiles(folderPath).OrderBy(Function(f) Path.GetFileName(f)).ToArray()
Directory.GetFiles is the smallest reliable tool for collecting file lists in UiPath. Assign a folderPath call Directory.GetFiles apply a pattern loop with For Each and handle exceptions with Try Catch. Add LINQ if you want sorting and filtering without spaghetti logic. Now go automate something mildly heroic and let the robot handle the boring bits.
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.