import os
#遍历文件夹
def listFilename2(path1,treeshow): #加入参数treeshow
fileList=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","")
Python 递归,遍历文件夹有层次感
最新推荐文章于 2024-05-01 09:35:06 发布