Skip to content

Instantly share code, notes, and snippets.

@Navid-JL
Created September 21, 2023 18:05
Show Gist options
  • Select an option

  • Save Navid-JL/c7dc331cf2b31dcd93c73ceafcdff580 to your computer and use it in GitHub Desktop.

Select an option

Save Navid-JL/c7dc331cf2b31dcd93c73ceafcdff580 to your computer and use it in GitHub Desktop.
Directory Tree Generator
|--
| |-- main.py
| |-- script.ipynb
|-- .vscode
| |-- settings.json
|-- test
| |-- test.py
def generate_directory_tree(root_dir):
for dirpath, dirnames, filenames in os.walk(root_dir):
depth = dirpath.count(os.sep) - root_dir.count(os.sep)
print("| " * depth + "|-- " + os.path.basename(dirpath))
for filename in filenames:
print("| " * (depth+1) + "|-- " + filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment