Skip to content

Add a directory tree printer (recursion exercise) #13

Description

@utk2103

Add a script that prints a directory as an ASCII tree, like the Unix tree command.

Why

Best small exercise in recursion there is — and the output is immediately satisfying. It also pairs with the "Repository Structure" section of our README, which is currently maintained by hand.

Suggested file

scripts/directory_tree.py

What it should do

  • Usage: python scripts/directory_tree.py . --max-depth 2
  • Print the tree with ├──, └──, │ connectors.
  • Skip noise by default: .git, __pycache__, .ipynb_checkpoints, .DS_Store.

Example output

Python-for-beginners/
├── data/
│   └── sample.txt
└── scripts/
    └── directory_tree.py

Acceptance criteria

  • Recursive (or an explicit stack) — not a hardcoded two-level loop.
  • Directories listed before files, each group sorted alphabetically.
  • --max-depth respected; standard library only (pathlib/os, argparse).

Inspiration

Directory_Tree_Generator from Awesome-Python-Scripts.

Good first issue — comment below to get assigned.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions