fullpath = os.getcwd()
fp_len = len(fullpath)
+tree = ('', [])
+current_subtree = tree[1]
+save_level = 0
+
for dirpath, dirs, files in sorted(os.walk(fullpath)):
try:
dirpath = dirpath[fp_len:]
raise StopIteration
parts = dirpath.split('/')
level = len(parts) - 2
- print ' ' * level + parts[-1]
+ if level < save_level:
+ current_subtree = tree[1]
+ for i in range(level):
+ current_subtree = current_subtree[-1][1]
+ current_subtree.append((parts[-1], []))
+ elif level == save_level:
+ current_subtree.append((parts[-1], []))
+ elif level > save_level:
+ assert level - save_level == 1
+ current_subtree = current_subtree[-1][1]
+ current_subtree.append((parts[-1], []))
+ save_level = level
except StopIteration:
pass