could ildg wrote: > I want to know this because I want to zip a directory and all of its > sub-files and sub-directories to a zip file. zipfile module of python > will not automatically include the empty directories, so I have to > check if a dir is empty and do this manually....
Can you make work some variant of: wanted, stack = {}, () for root,dirs,files in os.walk('.'): if files: # Don't worry about parent dictionaries for name in reversed(stack): if name in wanted and (root.startswith(name) and root[len(name)] == os.path.sep): del wanted[name] stack.pop() else: break else: wanted[root] = True print root, dirs, len(files) while len(stack) and not (root.startswith(stack[-1]) and root[len(stack[-1])] == os.path.sep): stack.pop() stack.append(root) --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list