I was always confused about directory traversal in Python and had a situation in which I was curious: I have a file that I want to get in a directory essentially parallel to the one I am currently in. Given this directory structure:
\parentDirectory \subfldr1 -testfile.txt \subfldr2 -fileOpener.py
I am trying to script in fileOpener.py to exit subfldr2, get into subfldr1, and then call open () on testfile.txt.
From viewing stackoverflow, I saw that people use os and os.path to accomplish this, but I found sample files in subdirectories under the script source.
While working on this, I realized that I can just move the script to subfldr1, and then everything will be fine, but my curiosity is caused by how this is achieved.
EDIT: This question applies in particular to a Windows machine, since I don't know how disk factors and backslashes will affect this.
source share