Python error: Cannot find the file specified

十年热恋 提交于 2019-12-24 07:52:32

问题


This is my body of code:

os.chdir("C:\\Users\\Desktop")

rc = subprocess.call(['7z', 'a', 'test', '-y', 'myarchive.zip'] +
                     [r'device teams.txt'])

It gives me an error pointing to r'device teams.txt' saying the specified file does not exist.

I checked the directory and it is in the desktop directory so I am not sure why it is giving me this error


回答1:


Based on your comments, the problem isn't the txt file path, it's that the command 7z cannot be found. You can check this by just calling rc = subprocess.call(['7z']): the error The system cannot find the file specified persists.

Here's how you can achieve the same thing using PowerShell for example:

import os
import subprocess
os.chdir("C:\\Users\\Username\\Desktop")
rc = subprocess.call("powershell Compress-Archive -Path 'device teams.txt' -DestinationPath archive.zip")


来源:https://stackoverflow.com/questions/55838168/python-error-cannot-find-the-file-specified

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!