-
-
Save prahladyeri/76833cfa80490b1753563ad15534eb97 to your computer and use it in GitHub Desktop.
Python-3 implementation of the tree linux command
This file contains 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 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