# HG changeset patch # User Jeff Hammel # Date 1376345650 25200 # Node ID c461ffb7af8cb24d41634ee0462f463cf54e074c # Parent 983f9d4fd4e887ad5d37ea9965e463ce4e394c66 adding path utilities diff -r 983f9d4fd4e8 -r c461ffb7af8c python/path.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/path.py Mon Aug 12 15:14:10 2013 -0700 @@ -0,0 +1,25 @@ +#!/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)