File system · 9 / 15 Exercise Hard

Directory tree

Objective

The program runs inside a folder that already contains the files of the test case. A recursive function that walks the folder, sorts its entries and calls itself with each subfolder prints the whole tree; the depth level decides the indentation.

Instructions

  • Show the whole content of the current folder, sorted by name at each level.
  • Each level is indented 2 more spaces than the previous one, and folders end with a /.
  • After a folder its content is shown right away.

Example. With main.py, src/app.py, src/util/tools.py and README.md it shows README.md, main.py, src/, app.py (2 spaces), util/ and tools.py (4 spaces).

Output
README.md
main.py
src/
  app.py
  util/
    tools.py

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise