Question

this very weird problem my code works fine in my machine (Linux mint) but it shows error in my server

here's the code -note i've make it abspath even it was works fine without it in my machine !

def GET_Contents(filepath):
    return os.listdir(os.path.abspath(os.path.join('files', filepath.strip())))

here's the the given exception return os.listdir(os.path.abspath(os.path.join('files', filepath.strip()))) OSError: [Errno 2] No such file or directory: '/home/hamoud/webapps/FileManager/files/EE201/MID 1'

the problem occurs only with the folders that contains spaces (like MID 1)

Was it helpful?

Solution

Spaces are fine and allowed in Windows paths too.

You need to verify that your working directory is correct (since you use a relative path, os.path.abspath() will base the absolute path of the current working directory in that case).

If the base path is correct, check that there really is a MID 1 directory at that location. Perhaps check the parent directory with os.listdir(os.path.abspath('files')) first to see what is really located there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top