递归遍历目录

import os
def gci(filepath):
#遍历filepath下所有文件,包括子目录
    files = os.listdir(filepath)
    for fi in files:
        fi_d = os.path.join(filepath,fi)
        if os.path.isdir(fi_d):
            gci(fi_d)
        else:
            print(os.path.join(filepath,fi_d))
            with open('z.txt',mode='at',encoding='utf-8') as f:

                f.write(os.path.join(filepath,fi_d)+'\n')

文章标题:递归遍历目录
文章地址:http://pwwzsj.com/article/iihhip.html