pthon 将目录按照树形结构打印出来,类似于tree命令
一、代码
import os
import os.path
def dfs_showdir(path, depth):
if depth == 0:
print("root:[" + path + "]")
for item in os.listdir(path):
if '.git' not in item:
print("| " * depth + "|--" + item)
newitem = path + '/' + item
if os.path.isdir(newitem):
dfs_showdir(newitem, depth + 1)
if __name__ == '__main__':
dfs_showdir(r'D:\****\deep_sort_pytorch', 0)
二、结果
|--configs
| |--deep_sort.yaml
|--deep_sort
| |--deep
| | |--checkpoint
| | | |--ckpt.t7
| | |--evaluate.py
| | |--feature_extractor.py
| | |--model.py
| | |--original_model.py
| | |--test.py
| | |--train.jpg
| | |--train.py
| | |--__init__.py
| | |--__pycache__
| |--deep_sort.py
| |--log3.txt
| |--README.md
| |--sort
| | |--detection.py
| | |--iou_matching.py
| | |--kalman_filter.py
| | |--linear_assignment.py
| | |--nn_matching.py
| | |--preprocessing.py
| | |--track.py
| | |--tracker.py
|--LICENSE
|--README.assets
| |--20200412221106751.png
| |--2020041418343015.png
| |--20200415100437671.png
| |--DeepSort.jpg
|--README.md
|--tree.md
|--utils
| |--asserts.py
| |--draw.py
| |--evaluation.py
| |--io.py
| |--json_logger.py
| |--log.py
| |--parser.py
| |--tools.py
| |--__init__.py
Process finished with exit code 0