Loop through images in a folder get text using ocr

Hi guys, new to the forum, firsts post, after looking at examples and trying a bunch of them I can’t seem to get my sequence to work, so I’m reaching out for help!

I want to loop through a folders contents (jpg for now later pds too)and use ocr to to get the text from the images and save it to .txt files, but I get a exception saying no files in the folder, but they are definitely there?

Tired for loops and for each loops, but no luck, can anyone perhaps provide a working example, I’ll be happy to share my activity flow when my power comes back on, we have issues in my country with electricity availability lol!

@Ray_Shadow Welcome to the community!

Directory.GetFiles(folderpath,“*.jpg”) should definitely give you the list of .jpg files in that folder, if you can share more details we can see what could be the reason for the error

Hi @Ray_Shadow

Directory.getdirectories(Mainfolderpath,“.”,searchoption.alldirectories) and assign to an array varaible to fetch all folders

2.use for each for the above created array
Inside for each use

and assign this to an array to fetch all files
Use another for each place read pdf text ocr activity

Hope this helps

Hi @Ray_Shadow ,
You can try
or “.png”

Hello @Ray_Shadow ,
You can use For Each File in Folder activity and specify the Path of the Folder which contains all the Files, then you can use the OCR activities to Extract the data from the File.

Thanks I got it working, it was the second argument (Directory.GetFiles(folderpath,“.jpg”)) I was missing, this “.jpg”

There are also older examples here that no longer work or support UIPathDocumentOCR that also had me using OCR that is not to great, but all working now!

Thanks so much!

1 Like

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