python 读取文件名并写入xlsx

# -*- coding: utf-8 -*-
import os

def listdir(path, list_name):  
    for file in os.listdir(path):  
        file_path = os.path.join(path, file)  
        if os.path.isdir(file_path):  
            listdir(file_path, list_name)  
        elif os.path.splitext(file_path)[1]=='.png':  
            list_name.append(file_path)
            
def writefile(list):
    f=open("d:/14.xlsx","w+")
    for i in list:    
        f.writelines(i[35:][:-4]+'\n')
    f.close()
    
path="D:\最终图\通道图\AM-001"
list=[]
listdir(path,list)
writefile(list)

你可能感兴趣的:(python)