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')
转载于:https://blog.51cto.com/14127188/2342748