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

2019-04-15 16:50发布

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] + ' ') write_file.close()