永久会员
- 威望
- 3416
- 贡献
- 5109
- 热心值
- 0
- 金币
- 3121
- 注册时间
- 2019-8-13
|
前几天下了一个:程序猿必知必会-MySQL 8.0详解与实战,里面的文件只有编号没有内容,不方便查看,用python搞了个小脚本批量重命名。
- import os
- path = "D:\BaiduYunDownload\【瑞客论坛 www.ruike1.com】程序猿必知必会-MySQL 8.0详解与实战"
- filenames = os.listdir(path)
- # for filename in filenames:
- # filename = path + '\\' + filename
- # print(os.path.isfile(filename))
- # print(filenames)
- with open('listname.txt', encoding='utf-8', mode='r') as f:
- listnames = f.readlines()
- for filename in filenames:
- filetype = '.mp4'
- splitedfilename = filename.split('【')
- sfn0 = splitedfilename[0]
- for listname in listnames:
- # splitedliciwstname = listname.split(' ')
- sln0, *sln1 = listname.split(' ')
- ssln1 = ''.join(sln1)
- # sln0 = splitedlistname[0]
- # *sln1 = splitedlistname[1:]
- if sfn0 == sln0:
- newfilename = sfn0 + ssln1 + filetype
- newfilename = newfilename.replace('\n', '').strip()
- newfilename = path + '\\' + newfilename
- filename = path + '\\' + filename
- print(os.path.isfile(filename))
- print(newfilename)
- os.rename(filename, newfilename)
复制代码 主要思路是找出原始文件名和官网上的文件名重复的部分,匹配后用官网正确的文件名替换。
|
|