You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
704 B

11 months ago
# -*- coding: utf-8 -*-
# Time : 2023/11/9 11:54
# Author : lirunsheng
# User : l'r's
# Software: PyCharm
# File : demo13.py
import os
# 读取文件夹中的图像文件名到列表
def get_image_filenames(folder_path):
image_filenames = []
for file_name in os.listdir(folder_path):
# 检查文件类型是否为图像类型(这里使用了简单的判断方式)
if file_name.endswith('.jpg') or file_name.endswith('.png'):
# 将文件名添加到列表中
image_filenames.append(file_name)
return image_filenames
# 调用函数来获取图像文件列表
image_files = get_image_filenames('K:/工作/traveler/background/')
print(image_files)