Created
February 27, 2023 17:05
-
-
Save ivanistheone/0b9b3c003766f5bc9323cdcb925afafa to your computer and use it in GitHub Desktop.
Revisions
-
ivanistheone created this gist
Feb 27, 2023 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ #!/usr/bin/env python import argparse import os def tree(directory=".", indent = " "): """ Helper function that prints the filesystem tree. """ ignorables = ["__pycache__", ".gitignore", ".DS_Store", ".ipynb_checkpoints", ".git", "venv"] for root, dirs, files in os.walk(directory): path = root.split(os.sep) if any(ign in path for ign in ignorables): continue print((len(path) - 1) * indent, os.path.basename(root) + "/") for file in files: if file in ignorables: continue print(len(path) * indent, file) if __name__ == "__main__": parser = argparse.ArgumentParser(prog = 'tree', description = 'list contents of directories in a tree-like format.') parser.add_argument('directory', nargs='?', default=".") args = parser.parse_args() tree(args.directory)