os.listdir & os.stat fail on windows zipdrive
Albert Wagner
alwagner at tcac.net
Thu Apr 20 21:03:35 EDT 2000
Crap, I forgot the code:
def descendTree(self, dir):
'''
recursively descend the directory tree rooted at dir,
save each directory and its files as an entry in a Dictionary.
Each directory pathname is a key with a List for a value.
Each filename is placed in the list for its directory.
'''
self.tree[dir] = []
for aName in os.listdir(dir):
dirName = '%s/%s' % (dir, aName)
try:
mode = os.stat(dirName)[ST_MODE]
except:
self.tree[dir].append("(%s)" % aName)
continue
if S_ISDIR(mode):
if not self.tree.has_key(dirName):
self.tree[dirName] = []
# recurse into directory
self.descendTree(dirName)
elif S_ISREG(mode):
self.tree[dir].append(aName)
else:
self.tree[dir].append("(%s)" % aName)
--
Small is Beautiful
More information about the Python-list
mailing list