import csv
import shutil
import os
target_path = '.\\'#目标文件夹
original_path = '.\\train\\train\\'#原始文件夹
with open('.\\train\\train_sorted.csv',"rt", encoding="utf-8") as csvfile:
reader = csv.reader(csvfile)
rows= [row for row in reader]
for row in rows:
if os.path.exists(target_path+row[1]) :
full_path = original_path + row[0]
shutil.move(full_path,target_path + row[1] +'/')
else :
os.makedirs(target_path+row[1])
full_path = original_path + row[0]
shutil.move(full_path,target_path + row[1] +'/')
根据csv文件按照标签划分文件夹数据集
最新推荐文章于 2024-05-15 13:58:42 发布