import os#加载文件操作模块
def findfile(file_path):
listRs=os.listdir(file_path)#得到该路径下面所有的文件夹
for fileitem in listRs:
full_path=os.path.join(file_path,fileitem)#获取完整的文件路径
if os.path.isdir(full_path):#判断是否是文件夹
findfile(full_path)#如果是一个文件夹 再次去递归
else:
print(fileitem)
pass
else:
return#没有就直接返回
#调用搜索文件夹对象
findfile('E:\\新建文件夹 (2)\自己选的文件夹名')
#递归案例 模拟实现树形结构遍历
最新推荐文章于 2023-06-17 20:58:01 发布