下面是一个使用Python的解决方案,它可以遍历包含图片的文件夹,并将文件名写入一个.csv文件。
import os
import csv
def traverse_folder(folder_path):
# 创建一个空的csv文件
with open('image_files.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(["File Name"]) # 写入表头
# 遍历文件夹中的所有文件
for root, dirs, files in os.walk(folder_path):
for file in files:
# 检查文件是否为图片文件
if file.endswith('.jpg') or file.endswith('.png') or file.endswith('.jpeg'):
# 将文件名写入csv文件
writer.writerow([file])
print("遍历完成,并将文件名写入image_files.csv文件。")
# 指定要遍历的文件夹路径
folder_path = '/path/to/folder'
# 调用函数进行遍历,并将文件名写入csv文件
traverse_folder(folder_path)
请将 folder_path
变量替换为要遍历的文件夹的实际路径。运行代码后,将在当前目录下生成一个名为 image_files.csv
的.csv文件,其中包含了所有图片文件的文件名。