在Sikuli中打开(显示)pdf文件

时间:2019-03-05 15:02:42

标签: python jython sikuli

我想从Sikuli的pdf文件目录中的Adobe Reader阅读器pdf文件中打开(显示)。 我设法对一个文件执行此操作:

import os
import subprocess 

file = 'C:/Users/.../pdf/test3.pdf'
subprocess.Popen([file],shell=True) 

这很好。

现在,我要为目录中的每个pdf文件执行此操作。 到目前为止,这是我的代码:

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)

但是它不起作用。有人可以帮我弄清楚for语句吗?

提前谢谢!

1 个答案:

答案 0 :(得分:1)

尝试一下:

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)

您需要提供pdf文件的完整路径,而不仅仅是文件名。

相关问题