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

farbod

this code moves all pdf files into a folder called pdf.It moves the first file then get error for moved file: [WinError 2] The system cannot find the file specified: 'C:\Users\farbod\Desktop\Print Form.pdf' -> 'C:/Users/farbod/Desktop/pdf/Print Form.pdf' note: I also used shutil instead of pathlib.Same error



import os
from pathlib import Path




path ="C:/Users/farbod/Desktop"
pdf_folder_path = "C:/Users/farbod/Desktop/pdf"
files=[]

os.chdir(path)
files = os.listdir(path)
for file in files:
    file_path= path + '/' + file
    file_name,file_ext= os.path.splitext(file_path)
    if file_ext==".pdf":
        os.rename(file_path,pdf_folder_path+'/'+file)
        Path(file_path,).rename(pdf_folder_path+'/'+file)
    else:
        continue

Ghost Ops

I think this is the code you are looking for

Tell me if there's any errors

import os
# from pathlib import Path

os.chdir("C:/Users/farbod/Desktop")
files = os.listdir()
for file in files:
    if file.split('.')[-1] == "pdf":
        os.rename(file, f"/pdf/{file}")
        # Path(file).rename(f"/pdf/{file}")
        # I can't understand why you have to move a file using 2 same functioning lines
        # (or guess what, i don't know to use pathlib. os.rename is enough to move a file)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

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

How to fix "CreateProcess error=2, The system cannot find the file specified" even if the Path variable is specified (crossplatform)

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

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

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

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

Error:java: Cannot run program CreateProcess error=2, The system cannot find the file specified

Can't run any ipynb files using Jupyter Lab or Jupyter Notebook (FileNotFoundError: [WinError 2] The system cannot find the file specified)

SQL Server on Ubuntu 18.04 Operating system error 2(The system cannot find the file specified.)

Subprocess The system cannot find the file specified Error

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

How to fix FileNotFoundError: [WinError 2] The system cannot find the file specified

FileNotFoundError: [WinError 2] The system cannot find the file specified: exiftool

python check_output FileNotFoundError: [WinError 2] The system cannot find the file specified

FileNotFoundError: [WinError 2] The system cannot find the file specified when using export_graphviz

Python venv env Fails - [WinError 2] The system cannot find the file specified

Blackberry Error: Cannot run program "jar": CreateProcess error=2, The system cannot find the file specified

Arduino Sublime Text 2. I can compile but can't upload. Error "The system cannot find the file specified"

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

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

Using Image (Pillow)/Pytesseract (Python): FineNotFound: [WinError 2] The system cannot find the file specified

Calling subprocess.call(...) yields in error "[WinError 2] System can't find the specified file"

FileNotFoundError: [WinError 2] The system cannot find the file specified while loading model from s3

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

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

Can't solve FileNotFoundError: [WinError 3] The system cannot find the path specified: Error Python

Python : FileNotFoundError [WinError 2] The system cannot find the file specified , subprocess.py:1582

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

IntelliJ - Cannot run program java.exe. CreateProcess error=2. The system cannot find the file specified