For each file in each subfolder

How do I run a certain activity (Google vision OCR) on every file within each subfolder, while all the subfolders are within the same folder?

Hi @AdamKA

Suppose your all subfolders are inside C:\TestFolder

Directory.GetFiles("C:\TestFolder", "*", SearchOption.AllDirectories)

The above code will give the path of all files within the TestFolder and the Folders inside it.

So, you will need only one for loop

image

1 Like

That is a very useful method. But I need to process each subfolder separately. I am running all the JPGs in each subfolder through an OCR and sending the output to a separate Word doc. So there will be one text file created from scanning all the images within each subfolder. And ideas?

Hi @AdamKA

In your workflow, in the outer for loop use Directory.GetDirectories(path) method to get all subfolders path inside the main folder.

Then, the in the inner loop use directory.getfiles(folder) to get all the files inside the subfolder for the current subfolder in iteration

To write the text file use the path β†’ folder.ToString+"\filename.docx"

Outer For Loop β†’ ForEach folder in Directory.GetDirectories("C:\TestFolder")
Innder For Loop-> ForEach file in Directory.GetFiles(folder.ToString)
Path in WAS β†’ folder.ToString+"\out.docx"

That’s exactly what I needed! Thanks very much

@AdamKA

Mark the post as solution to close the topic.