# -*- coding: utf-8 -*- import os file_dir = "D:\\SHU-results-20190401" def file_name(file_dir): for root, dirs, files in os.walk(file_dir): print("root is ",root) # 当前目录路径 print("dirs is ",dirs) # 当前路径下所有子目录 print("files is ",files) # 当前路径下所有非目录子文件 f=open("D:/research/code/pathdata.xlsx","w+") for i in files: f.writelines(i[:][:-4]+'\n') #将文件后缀去掉 f.close() file_name(file_dir)
运行结果案例: