递归遍历目录
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://scjbc.cn/article/iihhip.html