Python 打印树形目录结构 (linux 下目录形式)
Python 打印树形目录结构 (类似 linux 下目录的形式)
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('I:\**python****', 0)
结果:
参考: