view python/_path.py @ 847:6c918c07d0e3

[gpg] make a front-end to add a line to a gpg symmetrically encrypted file
author Jeff Hammel <k0scist@gmail.com>
date Tue, 17 Oct 2017 11:59:09 -0700
parents ebca6d85213a
children
line wrap: on
line source

#!/usr/bin/env python

"""
(filesystem) path utilities

from http://stackoverflow.com/questions/12041525/a-system-independent-way-using-python-to-get-the-root-directory-drive-on-which-p
"""

import os

def is_root(path):
    """is `path` the filesystem root"""
    return not os.path.split(path)[1]

def root(path):
    """return filesystem root of path"""
    path = os.path.abspath(path)
    while not is_root(path):
        path, tail = os.path.split(path)
    return path

if __name__ == '__main__':
    import sys
    for path in sys.argv[1:]:
        print root(path)