Python复制单个文件为多个脚本

Python复制单个文件为多个脚本,第1张

编写背景:

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

代码如下:

# 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()

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/langs/717329.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-04-25
下一篇2022-04-25

发表评论

登录后才能评论

评论列表(0条)

    保存