Created
April 2, 2017 01:48
-
-
Save klange/f5c1c95fddce9fd21a51535ebea9d0a6 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/python | |
""" | |
tree.py - List directories in a visual tree. | |
""" | |
import os | |
def print_directory(path, prefix="", last=False): | |
if last: | |
extra = "└─" | |
else: | |
extra = "├─" | |
print(f"{prefix}{extra}{os.path.basename(path)}") | |
if not last: | |
prefix += "│ " | |
else: | |
prefix += " " | |
if os.path.isdir(path): | |
subs = os.listdir(path) | |
for i in range(len(subs)): | |
p = os.path.join(path,subs[i]) | |
if i == len(subs)-1: | |
print_directory(p,f"{prefix}",True) | |
else: | |
print_directory(p,f"{prefix}",False) | |
print_directory(".",last=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment