【Python】提取图片文件名并写入txt中

import os

file_path = "数据路径" 
path_list = os.listdir(file_path) 

path_name = []

for i in path_list:
    path_name.append(i.split(".")[0]) 


for file_name in path_name:
    with open("dataset.txt", "a") as file:
        file.write(file_name + "\n")
        print(file_name)
    file.close()

    原文作者:ericdiii
    原文地址: https://blog.csdn.net/ericdiii/article/details/124776715
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞