如何获取Python中给定目录中所有文件(和目录)的列表?
我开始在安装了 cygwin(Python 2.7)的 Windows 7 x64 机器上开发一个小的 pdf 到 jpg 脚本。以下工作完美:
import subprocess
filename = "test"
subprocess.check_output('gs -sDEVICE=jpeg -dPDFFitPage -g2800x3620 -o ' + filename + '-2800-%03d.jpg ' + filename + '.pdf', stderr=subprocess.STDOUT)
Run Code Online (Sandbox Code Playgroud)
在我的 Windows 10 x64 非 Cygwin 机器(Python 2.7)上拉取此项目后,此代码错误,因为它不再将“gs”识别为 ghostscript 的内置缩写。所以我尝试以下操作:
import subprocess
filename = "test"
subprocess.check_output('C:\Program Files\gs\gs9.20\bin\gwin64c.exe -sDEVICE=jpeg -dPDFFitPage -g2800x3620 -o ' + filename + '-2800-%03d.jpg ' + filename + '.pdf', stderr=subprocess.STDOUT)
WindowsError: [Error 2] The system cannot find the file specified
Run Code Online (Sandbox Code Playgroud)
好吧,我是初学者,在这里犯了一些明显的错误。"\b"中间的字符也.20\bin\被突出显示......向我表明我不知何故没有明确这是一条单一的路径。
我也尝试过的事情(单独运行): …
cmd ×1
directory ×1
executable ×1
file ×1
python ×1
python-2.7 ×1
subdirectory ×1
subprocess ×1
windows ×1