I know that we can use os.walk() to list all sub-directories or all files in a directory. How can I generate a tree structure as follows rather than just listing all the directories? In some sub-directories I have hundreds of files, so how can I show only few files within the sub-directory without listing them all?
doc/
├── _static/
│ ├── embedded/
│ │ ├── deep_file
│ │ └── very/
│ │ └── deep/
│ │ └── folder/
│ │ └── very_deep_file1
| | └── very_deep_file2
| | └── ......
│ └── less_deep_file
├── about.rst
├── conf.py
└── index.rst
The following may be help you: