# -*- coding:UTF-8 -*-
# author:
# contact:
# datetime:
# software: PyCharm
"""
文件说明:
打印工程目录文件,参考链接:
https://blog.csdn.net/albertsh/article/details/77886876
"""
import os
import os.path
def dfs_showdir(path, depth):
if depth == 0:
print("root:[" + path + "]")
# print("当前文件路径是{},包含文件有{}。".format(path, os.listdir(path)))
for item in os.listdir(path):
# 排除目录
if item in ['.git', '.idea', '__pycache__', 'venv', 'runs', 'newDatasetRoot']:
continue
# 排除文件类型
if item.split('.')[-1] in ['png', 'jpg', 'json', 'gif']:
continue
# print(item)
# print(item.split('.'))
print("│ " * depth + "└─ " + item)
# 写入文件
with open(r"C:\Users\Lenovo\AppData\Roaming\JetBrains\PyCharm2022.3\scratches\structure.txt", 'a+') as f:
f.write("│ " * depth + "└─ " + item + '\n')
new_item = path + '/' + item
if os.path.isdir(new_item):
dfs_showdir(new_item, depth + 1)
if __name__ == '__main__':
dfs_showdir("D:\projects\help\LexiconAugmentedNER-master", 0)