import os
import sys
def filelist(ptn):
debug = False
ptn = os.path.expanduser(ptn)
ptn = os.path.abspath(ptn)
if os.path.isfile(ptn):
if os.access(ptn, os.R_OK):
return [os.path.basename(ptn)]
return []
if os.path.isdir(ptn):
# The last '/' is already chopped
ret = []
for root, dirs, files in os.walk(ptn):
A = root.split(ptn, 1)
assert A[0] == ''
if A[1] == "":
rel_root = ""
else:
rel_root = A[1][1:]
for f in files:
f2 = os.path.join(root, f)
if os.path.isfile(f2):
if os.access(f2, os.R_OK):
ret.append(os.path.join(rel_root, f))
else:
if debug:
print >> sys.stderr, "%s is not accessible"%(f2)
else:
if debug:
print >> sys.stderr, "%s is not a file"%(f2)
return ret
return []
ret = filelist("~/ucp")
print ret
[an error occurred while processing this directive]