Python os.scandir() returns file or directory not found

paulspavan

Right off the assembly line
I am developing a flask app that scans a directory on local disk and performs some file operations. It works very well in Windows, but when I deploy to DigitalOcean (Linux) it gives the following error:

for file in os.scandir(path):
FileNotFoundError: [Errno 2] No such file or directory: '/my/directory/path'

The directory created in my Windows is:

D:\my\directory\path

So when I use the UNIX path for it /my/directory/path because my project is on my D disk so it considers it as root, it works perfectly.

On Linux, I literally just created the same path /my/directory/path, and it says directory not found.

Here is my python code:

def get_files(path):
print("CHECKING THE PATH: ", path)
for file in os.scandir(path):
if os.path.isfile(os.path.join(path, file)):
print("FILE YIELDED IS: ", file)
yield file
 
Last edited:
Top Bottom