Question on read text file naming

I have a very simple question but I am not finding a good answer.

I have a very simple issue. I want to read a bunch of text files in a folder.

so it’s something like:

For each file in folderpath, read text file and output to a string variable.

what do i put for file name in the read text file box? I don’t know what to do here. See attached for reference.

question.xaml (4.6 KB)

1 Like

2 things:

  1. You need to change the TypeArgument in your ForEach activity to be string.
  2. You put file in the read text file activity since that is the name you gave it in your ForEach activity

why would I make the typeArgument string if they are files and haven’t been converted to strings yet? Just trying to understand the logic behind that I am a bit confused thank you

@Thomas_Marzol - the TypeArgument should be string because you are telling UiPath what type of items are contained within the IEnumerable that you are iterating through.

I made the assumption that folderpath is an IEnumerable of strings. I assumed you were using Directory.GetFiles(“C:\YourFolderPath\GoesHere”) to get the list of files.

Since folderpath is an IEnumerable of strings (it’s a collection of file paths saved as strings), you need to tell UiPath that the variable you named file in your IEnumerable is of type string.

It’s important to remember that you aren’t iterating through actual files/applications. Instead, you are iterating through a list of strings pointing to the files

@Dave to help flush this out. I have attached a more elaborate file that has more of what I am trying to do.

What I am starting with is a folder of text files. These were generated via another OCR activity. That all is working great. What I need to do is for each file in the folder, read the text and see if the keyword “577” is present, if it is I do stuff, if it isn’t move onto the next file.

Another way of describing the problem is I need to start with a text file and end with a string I can read/parse/split/cut up, in an iterative fashion. I followed your advice and am running into a new error. I will follow up with specifics.questionrevised.xaml (5.8 KB)

on the for each loop the error it says is

"Unable to cast object of type “system.char” to “system.string”

that’s having it the way you stated.

questionrevised-dave.xaml (12.0 KB)

This includes annotations in here on what things are doing. Basically first you have a folderpath. This is a string and it is the folder/directory containing all of the files. Next, you want to get a list of all of the files in the folderpath. Then you want to iterate through each file within the folderpath, read the text file and check if it contains a specific keyword. If it contains the keyword, do stuff. If keyword is not found, leave it blank (do nothing) and move onto the next file in the folderpath.

I can help point out specific issues too, but please ask if you have any clarification questions on how something works or why I chose to do it. I tried to annotate to help with this, but it’s easier to ask questions :slight_smile:

Thanks Dave!