参考文章:https://www.pianshen.com/article/8682278869/
非常感谢
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('D:\MyLearning\PyCharm\myQt01', 0) # 这里输入需要导出目录结构的根路径**加粗样式**
本文介绍了一个使用Python编写的函数,它递归地显示指定目录及其子目录结构,不包括.git文件。适合理解目录操作和基础文件系统编程。
1000

被折叠的 条评论
为什么被折叠?



