Could not find file error

I’m trying to execute a process that reads text from each file in a folder. When setting this up, I assign FolderName = the location of the folder and Files = “Directory.GetFiles(FolderName)”. Then I start a For Each with ForEach item in Files and I have ResultSplit = System.IO.File.ReadAllText(item.ToString).

The error I’m getting says: “Could not find file” and then lists a file position different from the one I have typed into the assign. The error appears to be throwing at the first assign block inside the body of the loop in which I try to read the text file.

You have assigned a string to the Files object. Take off the quotes.

1 Like

It won’t run without the quotes. I get a validation error. Also, I have looped through a folder earlier in my code and it works with the quotes.

Hi
Kindly remove the double quotes for this expression
As it should be like this
Files = Directory.GetFiles(FolderName)
where Files is a variable of type array of string which will store all the filepath of files in that folder

—now pass this array variable to FOR EACH activity as input and change the type argument as string in the property panel

—inside the loop use a ASSIGN activity like this
ResultSplit = System.IO.File.ReadAllText(item.ToString)

Where if it’s a text file instead of this assign activity inside the for each loop we can use READ TEXT FILE activity and pass the input as item.ToString which will either give us the string in that text file as output variable

Cheers @rbran

Thank you for your help! Any idea what this error is referring to?

Yah change the variable type of File from string to Array of strings in the variable panel

Cheers @rbran

Thanks so much!

Cheers @rbran

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