这是我的代码主体:
os.chdir("C:\\Users\\Desktop")
rc = subprocess.call(['7z', 'a', 'test', '-y', 'myarchive.zip'] +
[r'device teams.txt'])
它给我一个指向 r'deviceteams.txt' 的错误,指出指定的文件不存在。
我检查了目录,它位于桌面目录中,所以我不确定为什么它给我这个错误
根据您的评论,问题不在于txt
文件路径,就是这个命令7z
找不到。您只需拨打电话即可检查rc = subprocess.call(['7z'])
: 错误The system cannot find the file specified
持续存在。
例如,以下是使用 PowerShell 实现相同目标的方法:
import os
import subprocess
os.chdir("C:\\Users\\Username\\Desktop")
rc = subprocess.call("powershell Compress-Archive -Path 'device teams.txt' -DestinationPath archive.zip")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)