FileNotFoundError: [WinError 3] The system cannot find the path specified

lcyilleub report abuse

I’m trying to rename a file with os.rename() in Python and I get this: FileNotFoundError: [WinError 3] The system cannot find the path specified: But I have this file here and with other files it works ok.

Answers

Regal_422 report abuse

Does your other files placed in the same folder? Make sure that you have relevant privacy setting on that file.

lcyilleub report abuse

Yes, it’s a set of pictures and I take them from a folder in a loop. All files in the folder are available to read from Python. I didn’t change privacy settings for the specific file.

erikpal report abuse

You can try to use full path instead of relative path. It solved this for me.

lcyilleub report abuse

I use the full path. I also look for files in the destination folder several times in a loop and only a few files get an error.

Regal_422 report abuse

Can you please show a full code sample?

lcyilleub report abuse

My code ``` import os import glob

path = 'C:\Users\User\Documents\projectsdata\datasets\mydatasets\objectrecognition\creatorbot\b1331001\userspictures\autosaved\newpicturesto_update\2020-05-12'

i = 0 for srcpath in glob.glob(os.path.join(path, '*.jpg')): basename = os.path.basename(srcpath) dirname = os.path.dirname(srcpath) dstpath = os.path.join(os.path.dirname(srcpath), 'image'+str(i)+'.jpg') i += 1 os.rename(srcpath, dstpath) and an output Traceback (most recent call last): File "C:/Users/User/Documents/PycharmProjects/data/names.py", line 48, in os.rename(srcpath, dstpath) FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\Users\User\Documents\projectsdata\datasets\mydatasets\objectrecognition\creatorbot\b1331001\userspictures\autosaved\newpicturestoupdate\2020-05-12\AgACAgIAAxkBAAOsXisu2JiEIo8qNC4CqiYw2jxpPgAAo-sMRumx1lJWvdAoZ5AlyQAAWfLDgAEAQADAgADeQADDFQBAAEYBA.jpg' -> 'C:\Users\User\Documents\projectsdata\datasets\mydatasets\objectrecognition\creatorbot\b1331001\userspictures\autosaved\newpicturestoupdate\2020-05-12\image_4.jpg'

Regal_422 report abuse

It looks like a Windows file system error. Which version of Windows do you use?

BoiKo report abuse

Maybe your filename is too long. Can you open it from Windows Explorer?

lcyilleub report abuse

@Regal_422 I use Windows 10 Home.

lcyilleub report abuse

@BoiKo I can open all pictures from Explorer normally. I think you are right, I tried to rename this file and it works. Maybe I should move them to another folder before proceeding? I won’t be able to rename all files manually, I want to rename them with this script.

BoiKo report abuse

There is a limit to 260 characters in the MAX_PATH system variable for Windows 10. If you can’t change the path maybe you can try this https://betanews.com/2016/05/29/long-paths-windows-10/

lcyilleub report abuse

@BoiKo Thank you!

Add Answer

Need support?

Just drop us an email to ... Show more