I don't know how to do this with relative paths
First you need to get the directory path, so ...
Say you have this directory structure:
cur_directory |- setup.py |- inner_dir |- file2.py
To get the directory of the current file (in this case setup.py), use this:
cur_directory_path = os.path.abspath(os.path.dirname(__file__))
Then, to get the directory path relative to current_directory , just attach some other directories, for example:
inner_dir_path = os.path.join(cur_directory_path, 'inner_dir')
If you want to move up the directory, just use " .. ", for example:
parent_dir_path = os.path.join(current_directory, '..')
Once you have this path you can do os.listdir
For completeness:
If you need a file path, in this case " file2.py " relative to setup.py , you can do:
file2_path = os.path.join(cur_directory_path, 'inner_dir', 'file2.py')
source share