-
-
Save jmdeldin/145983 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
A poor man's directory tree for systems without the `tree` command. | |
:Author: Jon-Michael Deldin <[email protected]> | |
:Date: 2009-03-19 19:03 -0600 | |
""" | |
import sys | |
import os | |
def main(): | |
# CONFIG: | |
# directories to ignore | |
ignore = ['.hg', '.git', '.svn'] | |
# listing separator | |
separator = '| ' | |
try: | |
dir = sys.argv[1] | |
except: | |
dir = '.' | |
draw_tree(dir, ignore, separator) | |
def draw_tree(base_dir, ignore, separator): | |
""" | |
Prints a directory tree. | |
""" | |
base_dir = base_dir.rstrip('/') | |
for root, dirs, files in os.walk(base_dir): | |
for dir in dirs: | |
if dir in ignore: | |
dirs.remove(dir) | |
level = root.count(os.sep) | |
print separator * level + separator + os.path.basename(root) + '/' | |
for file in files: | |
print separator * (level + 1) + separator + file | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment