Bootstrap SomeTools Icon
返回
import tkinter as tk
from tkinter import filedialog
import os
import time
import shutil


class CopyVideo:
    def __init__(self):
        self.copy_num = 205
        self.copy_source_path = ""
        self.file_format = ""
        self.now_time = time.strftime("%Y-%m-%d_%H-%M-%S", time.localtime())

    def file_check(self):
        if not self.copy_source_path:
            root = tk.Tk()
            root.withdraw()
            self.copy_source_path = filedialog.askopenfilename(title="选择文件",
                                                               filetypes=[("mp4", "*.mp4"), ("mp3", "*.mp3"),
                                                                          ("wav", "*.wav")])
        else:
            if not os.path.exists(self.copy_source_path):
                raise ValueError("文件不存在")
        self.file_format = os.path.splitext(self.copy_source_path)[1].lower()

    def copy_file(self):
        os.makedirs(f"./{self.now_time}", exist_ok=True)
        # 复制文件
        success_count = 0
        for i in range(1, self.copy_num + 1):
            new_filename = f"媒资 第{i}集"
            copy_target_path = os.path.join(f"./{self.now_time}", new_filename)+self.file_format
            try:
                shutil.copy2(self.copy_source_path, copy_target_path)
            except Exception as e:
                print(f"{i}号文件出错,原因是{e}")
            else:
                success_count += 1
        print(f"总任务数:{self.copy_num},已成功:{success_count}")


try:
    copyVideo = CopyVideo()
    copyVideo.file_check()
    copyVideo.copy_file()
except Exception as error:
    print(error)