Need Help Looping thorugh PDF files in a folder

Hi, my process needs to loop through PDF files in a folder, read some data, use the data to rename the file, then move the renamed file to an output folder.

My first attempt was done using “Directory.GetFiles(In_FolderPath)” in a “For Each” loop but had issues so trying a different approach. I can grab the data I need but moving them becomes an issue - the move file says it can’t find it after I rename it and i even tried to move the file then rename it and still a no go.
So…

I now have it set up with “For Each File in Folder” loop but not sure how to set the the read to the current File - it gets mad at me.

Can someone help me?

Hi @Ashley_Bell

In the Read PDF Text activity give CurretFile.toString then the error will gone.

If you want to get the files which have pdf extension, then in the Filter by field give “*.pdf”, then only pdf files in the folder will come.

Hope it helps!!

1 Like

Steps to Loop Through PDF Files, Rename, and Move

  1. Use “For Each File in Folder” Loop:
  • This activity will loop through each file in the specified folder.
  • Ensure the folder path is correctly set.
    Inside the body of the loop make sure it is CurrentItem.FullName
  1. Read Data from the PDF:
  • Use appropriate PDF activities to read the required data from the current file.
    like read pdf text
    use logic to read and search for keyword using .equals or .contains method
  1. Rename the File:
  • Construct the new file name based on the data read from the PDF.
  1. Move the Renamed File:
  • Use the Move File activity to move the file to the output folder.

Hi

Please use CurrentItem.FullName it will fetch the full path of the file.
CurrentItem is FileInfo datatype. i.e the reason you are getting the error.

You can do the rename within the Move File activity by simply specifying the filename, not just the path, in the destination property of the Move File activity.

Thank you for your help!

1 Like

It’s my pleasure… @Ashley_Bell

If you find the solution Make my post Mark as solution to close the loop.

Happy Automation!!

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