Say the path of the file 'file1.txt' is /home/bentley4/Desktop/sc/file1.txt
Say my current working directory is /home/bentley4
import os
os.path.abspath('file1.txt')
returns /home/bentley4/file1.txt
os.path.exists('file1.txt')
returns False.
If I do
os.path.abspath('file_that_does_not_exist.txt')
It returns /home/bentley4/file_that_does_not_exist.txt
But again, this is not correct. The file does not even exist on my computer. Is there a way to get the correct absolute path from any directory I am currently working in? (aside from defining a new function)
So this only works when I am in the same directory as the existing file or in the directory one directory or more further from the path of the directory of that file?
os.path.abspathshould just work. What doesos.getcwd()return? ... Oh, d'oh, hang on, you're saying that you're in/home/bentley4and you're expectingos.path.abspathto somehow find a file in a sub-directory thereof? It doesn't do that. - torek