我有一个 python 脚本,它应该更新程序(清除文件夹并将新文件复制到其中)。它工作正常,但是当我运行从我的脚本(使用 py2exe)生成的 *.exe 文件时,它给了我一条错误消息:
Traceback (most recent call last):
File "update.py", line 10, in <module>
File "shutil.pyc", line 254, in rmtree
File "shutil.pyc", line 252, in rmtree
WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'C:\\Project\\MyProg\\Prog\\app'
这是我的脚本:
app = 'C:\\Project\\MyProg\\Prog\\app'
update = 'C:\\Project\\MyProg\\Prog\\update'
os.system("taskkill /im file.exe /f")
time.sleep(2)
shutil.rmtree(app)
shutil.move(update, app)
newpath = update
if not os.path.exists(newpath):
os.makedirs(newpath)
with open('info', 'w') as f:
f.write("updated")
subprocess.call(['C:\\Project\\MyProg\\Prog\\app\\file.exe'])