TypeError: argument of type 'WindowsPath' is not iterable - in open of pdf file with python

Viewed 20195

Good day,

I want to open the pdf files that have a specific name from a directory . These file names are provided from a csv file input, which are in the second column.

I tried the follwing code, but I received an error message:

TypeError: argument of type 'WindowsPath' is not iterable

How can I solve this problem and the pdf files to be opened according the input file?

And another issue: how can I fix if the input name is not an exact match with the pdf title,but I still want to open this file that contain the input name?

import csv
import os
from pathlib import *

dir_path = Path('D:\\path\\pdf files')
pdf_files = dir_path.glob('*.pdf')

file1=open('INPUT.csv','r')
reader=csv.reader(file1,delimiter=';')
for pdf_file in pdf_files:
    for item in reader:
        file_name=item[1]
        print(file_name)#just to see the file name that I want to open 
        if file_name in pdf_file:
            os.startfile("%s"%(pdf_file))
file1.close()

Thank you in advance!

1 Answers
Related