编写背景:

由于线上用户反馈媒体添加页加载时间很长,猜测是由于本地视频/图片数量过多引起,于是编写此脚本以便快速生成大量测试视频

代码如下:

# coding=utf-8
import os
import shutil
 
filePath = "/Users/ceshi/Downloads/Video/"
fileList = os.listdir(filePath)
filenum = int(input("Please enter number:"))
for i in fileList:
    name, extension = i.split(".")
 
 
def copyfile():
    for num in range(filenum):
        oldname = os.path.join(filePath, name + "." + extension)
        newname = os.path.join(filePath, name + str(num) + "." + extension)
        if os.path.exists(newname):
            continue
        shutil.copyfile(oldname, newname)
 
 
copyfile()