How to iterate text files in a folder to read

Hi all,
i have text files in a folder name with timestamps. I want to iterate through all of them. Then read and process them individually in each iteration. But i am not able to figure out how to iterate them. Could anybody suggest me any solution.


Buddy @akash.kumar

Welcome to UiPATH Community buddy…! Thats a great question to start with

  1. you can use Directory.Getfiles(“yourfolderpath”,"*.docx") in a assign activity with outvariable of type array of string named with out_file_path_array
    out_file_path_array = Directory.Getfiles(“yourfolderpath”,"*.docx")
    (i used docs, if it is a word document or you can use *.txt as well) @akash.kumar

  2. This would give you the array of file paths with which you can iterate through each file like if you want to open each file as well. using for each loop with input as this out_file_path_array and change the type argument as string in the for each loop buddy

Hope this would help you.
kindly try this and let know buddy @akash.kumar


Hello @akash.kumar

In Assign activity, please do this:

  1. Create a variable that is an Array of String (String). Let’s say arrFiles as the variable name
  2. In the Assign activity,
    arrFiles = Directory.GetFiles("folderPath", "*.txt")
  3. Use For Each activity to loop through the array
1 Like

Did that work for you buddy @akash.kumar

Hey @akash.kumar,

Futhermore, if you are iterating through For Each, to read the files you need item.ToString

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.