当前位置: 首页 > 工具软件 > xm-pic > 使用案例 >

python 读取项目文件目录Pic下的图片文件,将文件名写入文件

商飞尘
2023-12-01
from os import path
import sys
import os

def write_file_text():
    dpath = path.dirname(__file__)
    data_dir  =dpath +'/Pic/'
    file_list = []
    write_file_name = 'test.txt'
    write_file = open(write_file_name, "w",encoding="utf-8")
    tt=os.listdir(data_dir)
    for file in tt:
        if file.endswith(".jpg"):
            write_name = file
            for s_result in resulted:
                file_list.append(write_name)

    for current_line in range(len(file_list)):
         write_file.write(file_list[current_line] + '\n')
    write_file.close()

 

 类似资料: