Skip to content

Instantly share code, notes, and snippets.

@BjornFJohansson
Created June 10, 2015 09:57
Show Gist options
  • Save BjornFJohansson/f49aacf7cdc43a75c8f7 to your computer and use it in GitHub Desktop.
Save BjornFJohansson/f49aacf7cdc43a75c8f7 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
# tree.py
#
# Written by Doug Dahms
#
# Prints the tree structure for the path specified on the command line
from os import listdir, sep
from os.path import abspath, basename, isdir
from sys import argv
def tree(dir, padding):
print padding[:-1] + basename(abspath(dir)) + '/'
padding = padding + ' '
files = []
files = [x for x in listdir(dir) if isdir(dir + sep + x)]
count = 0
for file in files:
count += 1
print padding + '|'
path = dir + sep + file
if isdir(path):
if count == len(files):
tree(path, padding + ' ')
else:
tree(path, padding + '|')
else:
print padding + '+-' + file
tree("/home/bjorn/Downloads", ' ')
'''
webpy-markdown
|- app.py
|- pages
| |- index.txt
| `- other.txt
`- templates
`- page.html
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment