原因:有些视频文件固定文件前缀非常长,在播放器的播放列表里显示非常不友好。
场景:在 “D:\纪录片\中国通史” 路径下有100集视频文件,每个文件都带有固定前缀“www.baidu.com出品 微信公众号xxx”字样。
RemoveFixedPrefix.py
# coding=utf-8 import os # 目标路径 srcPath = "D:\纪录片\中国通史" fileList = os.listdir(srcPath) # 固定前缀 FixedPrefix = "www.baidu.com出品 微信公众号xxx" for fileName in fileList: oldFilePath = f"{srcPath}/{fileName}" # 跳过目录 if os.path.isdir(oldFilePath): continue newFileName = fileName.replace(FixedPrefix, "") newFilePath = f"{srcPath}/{newFileName}" try: os.rename(oldFilePath, newFilePath) except Exception as e: print(e) print(newFileName)
w
前两天有个50集的资源,视频文件+字幕一共50×2=100个前缀。当时想着这个绝对可以用编程来解决,可惜我不会,最后只能一个一个手动去前缀。
哈哈,希望对你有帮助