Skip to content

Instantly share code, notes, and snippets.

@prahladyeri
Created September 21, 2017 12:53
Show Gist options
  • Save prahladyeri/76833cfa80490b1753563ad15534eb97 to your computer and use it in GitHub Desktop.
Save prahladyeri/76833cfa80490b1753563ad15534eb97 to your computer and use it in GitHub Desktop.
Python-3 implementation of the tree linux command
#! /usr/bin/env python3
__author__ = "Prahlad Yeri"
__license__ = "MIT"
__version__ = "0.0.1"
import os, sys
def print_tree(dirname, pref = ""):
for item in os.listdir(dirname):
if item.startswith('.'): continue
print(pref + item)
if os.path.isdir(os.path.join(dirname, item)):
print_tree(os.path.join(dirname, item), " "*len(pref) + "+" + ("-"*5))
def main():
if len(sys.argv) == 1:
dirname = "."
else:
dirname = sys.argv[1]
print_tree(dirname)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment