递归——遍历文件夹

遍历文件夹——递归应用

import os
def read(filePath):
    it=os.listdir(filePath)  # 查看文件夹中文件
    for el in it:
        fp = os.path.join(filePath, el)
        if os.path.isdir(fp):  # 判断是文件还是文件夹
          print(el)
          read(fp)  # 递归入口
        else:
            print(el)  # 递归出口

猜你喜欢

转载自blog.csdn.net/qq_41813030/article/details/82960686