【图像分割】对文件夹进行批量处理

将文件名写入txt
对视频数据进行批量分类

代码

# 根据分类数据的名称获取视频数据

import os
import shutil


def writetxt(path, saveTxtPath):
    clsname = os.listdir(path)
    for i in range(len(clsname)):
        fileTxt = open(saveTxtPath + "/" + clsname[i] + ".txt", "w")    # 将文件名写入txt
        filePath = os.path.join(path, clsname[i])
        curr_name = None
        for filename in os.listdir(filePath):
            video_filename = filename.split("#")[0]
            if curr_name != video_filename:
                fileTxt.write(video_filename + "\n")                    
                curr_name = video_filename

        
# 对视频进行分类
def getVideo(path, videoPath, movePath):
    clsname = os.listdir(path)
    for i in range(len(clsname)):
        filePath = os.path.join(path, clsname[i])
        if not os.path.exists(os.path.join(movePath,  clsname[i])):
            os.makedirs(os.path.join(movePath, clsname[i]))

        file_arr = []
        curr_name = None
        for filename in os.listdir(filePath):
            file_filename = filename.split("_")[0]
            if curr_name != file_filename:     
                curr_name = file_filename
                file_arr.append(curr_name)
        for videoname in os.listdir(videoPath):
            _videoname = videoname.split(".")[0]
            if _videoname in file_arr:
                shutil.copy(videoPath + "/"+ videoname, movePath + "/" + clsname[i] + "/")



path = r"D:\Users\80080947\Desktop\yxLocalWork\AutoEF\A4C\Data\classificationData"
videoPath = r"D:\Users\80080947\Desktop\yxLocalWork\AutoEF\A4C\Data\heart_data\OriData"
movePath = r"D:\Users\80080947\Desktop\yxLocalWork\AutoEF\A4C\Data\heart_data\ProData"
getVideo(path, videoPath, movePath)

你可能感兴趣的:(python,开发语言)