Python error: Cannot find the file specified
Python error: Cannot find the file specified
这是我的代码主体:
os.chdir("C:\Users\Desktop")
rc = subprocess.call(['7z', 'a', 'test', '-y', 'myarchive.zip'] +
[r'device teams.txt'])
它给我一个指向 r'device teams.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")
这是我的代码主体:
os.chdir("C:\Users\Desktop")
rc = subprocess.call(['7z', 'a', 'test', '-y', 'myarchive.zip'] +
[r'device teams.txt'])
它给我一个指向 r'device teams.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")