Skip to content

Instantly share code, notes, and snippets.

@scionoftech
Created July 7, 2020 10:13
Show Gist options
  • Save scionoftech/aebe4a07f5bab2012bcc805c3ca5163a to your computer and use it in GitHub Desktop.
Save scionoftech/aebe4a07f5bab2012bcc805c3ca5163a to your computer and use it in GitHub Desktop.

Revisions

  1. scionoftech created this gist Jul 7, 2020.
    20 changes: 20 additions & 0 deletions dir_path.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    import os
    from os.path import dirname, abspath
    print("Path at terminal when executing this file")
    print(os.getcwd() + "\n")

    print("This file path, relative to os.getcwd()")
    print(__file__ + "\n")

    print("This file full path (following symlinks)")
    full_path = os.path.realpath(__file__)
    print(full_path + "\n")

    print("This file directory and name")
    path, filename = os.path.split(full_path)
    print(path + ' --> ' + filename + "\n")

    print("This file directory only")
    print(os.path.dirname(full_path))

    print(dirname(dirname(abspath(__file__))))