Open file one by one in a folder

Unlike going though a document where we can go down row by row until the last empty row is reached, how do we go about in opening the files one by one (followed by performing other action on the file opened) contained within a folder? and stop after the last file.

I would do the following:

  • Use ‘Get Folder Contents’ to output the list of files to a ‘List variable
  • Then use a ‘for-each’ loop to go through the list and open each file.
  • Use the ‘Read File’ action if they are text files or launch the application I need to use.
1 Like

thanks for the advice.
but ‘for-each’ loop does not have any file opening function built in.
And for ‘Read File’, need to specify the exact file locations, which cannot be used for my case. Where need to go down the list of different files which changes from time to time.

Get Folder Contents’ will give you the files with a full path

Here is a test recording I just put together as an example:
list-files.zip (1.5 KB)

Here is how the recording looks:
recording

And here is the output:
Output

1 Like

@ong_lee_wengfl then you can just use the variable ${item} as the path.

path-read-file

Dear Sir,

I need to display the files under in one folder, after listing the folder files list, the pdf files open one by one, and read the OCR, from the comparation of OCR
I have 4 different pdf files like in the format of voucher,invoice, License and agreement if its voucher, it will move to the voucher folder vice versa. in the loop…

so, please can you send me some workfusion sample codes.

Thanks in advance…have a nice day.

REgards,
D SUresh
mail: sureshd@nihontechnology.com

@abinaya_r do I understand correctly that you need to open each pdf file in the folder (there can be 4 types of files), read data using OCR, and then move the file to another folder, depending on which type of file it was?

1 Like

the type of pdf format is voucher,invoice, License and agreement.for example if its voucher, it will move to the voucher folder vice versa. in the loop…

the format is identify by OCR , if the OCR is Voucher it(the voucher pdf) will move to the
Voucher folder vice versa… invoice pdf, Agreement pdf and so on.

the type of file is Voucher, Invoice format , License Format , Certificate format …etc

please give sample code…thanks for your support…

REgards,
Abinaya

@abinaya_r try this approach:

  • create 4 groups of actions (voucher, invoice, license, agreement)
  • in each group, the bot will look for a specific image. If it find it - it OCRs the file and moves it to the required folder, marks the file as processed and skips all other actions. If it doesn’t find it - it skips the actions in this group and looks for another image and so on.

A sample script is attached (made with RPA Express 2.1.1)

ocr_loop.rar (55.8 KB)

1 Like

Thanks for your coding, I will check with your code, in case if I have a doubt , I will contact you.

Thanks for your support.

REgards,
Abinaya

1 Like

Thanks for Your support, I tried your ocr-loop, its running but while the file is not moving in the corresponding folder, please see the attachment .

Thanks for your valuable support. Have a nice day…

Regards,
Abinayaocr-loop.xlsx (617.2 KB)

I think it might be because the image is opened when you try to move it. Try adding action(s) to close it before moving.

Also, I noticed an error in my script above.
The “Agreement” group of actions has to be in the Then block, not Else.

thank you so much , its working fine now, thanks for your valuable support

have a nice day, god will be with you…

Regards,
D Suresh

1 Like

Hi,

is it possible to loop through file content, open up a pdf and use OCR to look for a particular pdf ( 2 types out of plenty other forms) and only move those 2 type of forms to a separate folder.

The OCR gives an error when it tries to read a different form in the folder and not the one its looking for.

Hi @trisha you can use Exception Handling in your script, so it doesn’t stop even if an action fails. So if the OCR is successful, the bot will move the file to a separate folder. If it is not, it will do nothing (or do other actions you need).

Hi, it isn’t running certain action.
Im currently working on opening a pdf( different pdf: invoice, receipt etc…) file, then reading the heading of the file (scanned image), if heading says “Invoice”, i want to close that pdf and move it to a separate folder. Is this possible ?

Do all invoices look absolutely the same? If yes, you can read the heading using OCR, or use Wait for image action to look for the header “Invoice”, and then use If-Else condition to perform different actions depending on what the bot saved in the variable after OCR, or whether the bot has found the header.

Hi @ashapkina
can you guide me how to proceed furthur in this scenario…
I have an tool where there will be some list of files and i need to open it one by one and some operations has to be performed over there.
if it is going to be an web action we can use xpath to loop over there or if it is going to be an folder content we can just use get folder content…but in this there is no option to add those files in list etc…
can you guide me some way for this?
Thanks in advance.

1 Like

@ashapkina Im also having this same doubt.
Can u pls help us

1 Like