I am trying to convert all pdfs in a folder into excel files. To do so, I am using the following code, though I am receiving the following error:
FileNotFoundError: [Errno 2] No such file or directory: 'filepath.pdf'
Here is the non-functioning code:
# import packages needed
import glob
!pip install tabula-py
import tabula
# set up working directory
my_dir = 'C:/Users/myfolderwithpdfs'
# transform the pdfs into excel files
for filepath in glob.iglob('my_dir/*.pdf'):
tabula.convert_into("filepath.pdf","filepath.xlsx", output_format="xlsx")
When I use either only the for loop to print the list of my files (as follows)
for filepath in glob.iglob('my_dir/*.pdf'):
print(filepath)
or tranform a single file
tabula.convert_into("myfilename.pdf", "myfilename.xlsx", output_format="xlsx")
I encounter no problems or errors with my code.