Python Forum

Full Version: File not found error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I wrote this code in eclipse / pydev. On running as Python Run it is throwing an error as

FileNotFoundError: [Errno 2] No such file or directory: 'TestEDI.txt'

import os.path
import shutil
from os import path

def main():

    print ("file exist:"+str(path.exists("C:/Users/Desktop/TestEDI.txt")))
       
#Copy a file with new name
newPath = shutil.copy('TestEDI.txt', 'C:/GNS082/Desktop/Test2Jan')
print ("file exist at new destination:"+str(path.exists('C:/Users/Desktop/TestEDI.txt')))
   
if __name__== "__main__":
   main()
Whats wrong with this code as it is working on my python IDLE on local system.

Thanks !
Adi
can you try putting full path of file and see if that helps, i doubt working directory would have been different when run from IDE causing the issue.


import os
print(os.getcwd()) #check working directory, if file not here, add full directory location for filename
newPath = shutil.copy(r'C:/Users/Desktop/TestEDI.txt', r'C:/GNS082/Desktop/Test2Jan')
Best Regards,
Sandeep

GANGA SANDEEP KUMAR
It worked.

Thanks Bro!
i have been getting the errno2 on my raspberry pi and pc using python 3 aswell i was following this tutroial.

https://maker.pro/raspberry-pi/projects/...en-display

can someone help me

Traceback (most recent call last):
File "C:\Users\user\Documents\hi.py", line 305, in <module>
window.resize_icons()
File "C:\Users\user\Documents\hi.py", line 284, in resize_icons
fp = open(original_path)
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\user\\Documents\\RaspberryPi-Noticeboard-master\\WeatherIconsclear-day.png'
Well, the file doesn't exist in that path. Are you sure that the path is correct?
Yes the directory does exist and all the WeatherIcons are located in that directory

You can try the tutorial from the link I provided and see if the same error comes for you.