I want to open (display) in adobe reader pdf files from my directory of pdf files in Sikuli. I manage to do this for one file:
import os
import subprocess
file = 'C:/Users/.../pdf/test3.pdf'
subprocess.Popen([file],shell=True)
This works fine.
Now, I want to do this for each pdf file in my directory. Here is my code so far:
import os
import subprocess
source = 'C:/Users/.../pdf'
for root, dirs, filenames in os.walk(source):
for file in filenames:
subprocess.Popen([file],shell=True)
But it is not working. Can someone plase help me to get the for
statement right?
Thank you in advance!
Try this:
import os
import subprocess
source = 'C:/Users/.../pdf'
for root, dirs, filenames in os.walk(source):
for file in filenames:
if file.endswith('.pdf'):
pdf_fullpath = os.path.join(root, file)
subprocess.Popen([pdf_fullpath],shell=True)
You need to provide fullpath of pdf file, not just the filename.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.