【发布时间】:2019-07-22 19:47:00
【问题描述】:
我正在使用 python 2.7 编写一些自动化代码,并将 glob、webbrowser 和 os 打包以使用 google chrome 下载链接。我下载文件没有问题,但是一旦下载,我的脚本就会吐出“'C:/Users/UserName/Downloads*'不被识别为内部或外部命令、可运行程序或批处理文件。”
脚本应该指向下载链接,下载文件,在下载文件夹中找到最近添加的文件,然后打开该文件。下载文件后出现问题,并且脚本由于某种原因从我的下载文件夹中打开文件时出现问题。以下是给我问题的脚本部分。这似乎是一个非常简单的问题,但我不知道为什么这个东西找不到我的下载文件夹。该程序在我的主 PC 上运行没有任何问题,但我无法将其移植到我的工作 PC。
elif choice == 'A' or choice == 'B' or choice == 'C':
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
file = ''
if choice == 'A':
file = A_file
if choice == 'B':
file = B_file
if choice == 'C':
file = C_file
webbrowser.get(chrome_path).open(file)
time.sleep(7)
list_of_files = glob.glob('C:/Users/UserName/Downloads*')
latest_file = max(list_of_files,key=os.path.getctime)
print 'Single file downloaded to location: '+ latest_file
print 'Opening file...'+"\n"
p = Popen(latest_file,shell='True')
【问题讨论】:
标签: python python-2.7 glob python-os python-webbrowser