Python 递归,遍历文件夹有层次感

来源:互联网 发布:乐知在线英语免费 编辑:程序博客网 时间:2024/05/17 23:37
import os#遍历文件夹def listFilename2(path1,treeshow):  #加入参数treeshowfileList=os.listdir(path1)for file in fileList:mypath=os.path.join(path1,file)  #连接成绝对路径if os.path.isdir(mypath):print(treeshow+mypath)treeshow+="--"    #将treeshow作为参数listFilename2(mypath,treeshow)   #递归else:print(treeshow+mypath)listFilename2("C:\\aa\\bb","")