file - get script directory name - Python - Stack Overflow

PHOTO EMBED

Wed May 25 2022 20:41:27 GMT+0000 (Coordinated Universal Time)

Saved by @HiTsH987 #python

currentFile = __file__  # May be 'my_script', or './my_script' or
                        # '/home/user/test/my_script.py' depending on exactly how
                        # the script was run/loaded.
realPath = os.path.realpath(currentFile)  # /home/user/test/my_script.py
dirPath = os.path.dirname(realPath)  # /home/user/test
dirName = os.path.basename(dirPath) # test
content_copyCOPY

https://stackoverflow.com/questions/31258561/get-script-directory-name-python