Python error: Cannot find the file specified

Afsheen Taheri

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

glhr

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")

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

The system cannot find the file specified windows error python

Subprocess The system cannot find the file specified Error

printf \'<a>\' gives error - cannot find the file specified

system cannot find the specified file python subprocess

WindowsError: [Error 2] The system cannot find the file specified, cannot resolve in Python

java.io.IOException: Cannot run program "python": CreateProcess error=2, The system cannot find the file specified

rename file in Python: WindowsError: [Error 2] The system cannot find the file specified

Python 3 - os.startfile() - WindowsError: [Error 2] The system cannot find the file specified: 'file_name'

CreateProcess error = 2, the system cannot find the file specified error

Flutter: Error: Error when reading '-': The system cannot find the file specified

Error message: createProcess error=2, The system cannot find the file specified

“git.exc.GitCommandNotFound: [WinError 2] The system cannot find the file specified” error in Python 3.5

pytesseract,WindowsError: [Error 2] The system cannot find the file specified

WindowsError: [Error2] The system cannot find the file specified

printf in nodejs execSync gives error - the system cannot find the file specified

CreateProcess error=2, The system cannot find the file specified

I get the error :[WinError 2] The system cannot find the file specified:

The System cannot find the file specified error while deleting folder

"The system cannot find the file specified" error on process.Start();

Sublime Text: "The system cannot find the file specified" error

Error: "The system cannot find the file specified" when using -r flag

Pyper error: [WinError 2] The system cannot find the file specified

Fatal error: Uncaught ImagickException: PDFDelegateFailed `The system cannot find the file specified

Google OATH2 Spreadsheet Error: Cannot Find Specified File

Makefile error (e=2): The system cannot find the file specified

What causes the error "The system cannot find the file specified"?

FindFirstChagneNotification cannot find specified file

pytesseract cannot find the file specified

Go cannot find file specified