import os
def thanAbsrelPath(f):
"Returns rhe absolute path of f, or, if f is in current dir, the relative path to f."
d = os.getcwd()
f = os.path.abspath(f)
if os.path.commonprefix((d, f)) == d: f = f[len(d)+1:]
return f
d = os.getcwd()
print "dir=", d
f = os.path.abspath("ok1/q1")
print "file=", f
c = os.path.commonprefix((d, f))
print "common=", c
if c == d:
f = f[len(c)+1:]
print
print "file ->", f
|