|
前几天下了一个:程序猿必知必会-MySQL 8.0详解与实战,里面的文件只有编号没有内容,不方便查看,用python搞了个小脚本批量重命名。# l! ^* M1 M! W4 Z, u1 R3 e* k
. K) _2 _' t% O& h
- import os# A+ d0 a, q$ C8 c& l* C- ?" D
- + F' ?6 ~: N$ ^7 u
- path = "D:\BaiduYunDownload\【瑞客论坛 www.ruike1.com】程序猿必知必会-MySQL 8.0详解与实战"5 x2 T# E% i2 h! j5 C# P
- filenames = os.listdir(path)+ J9 U+ E2 m$ X# K
- # for filename in filenames:+ I$ @; Q* W3 c5 ^' B7 p* U5 l0 A
- # filename = path + '\\' + filename5 a: W, F M" _9 e% r: V" F
- # print(os.path.isfile(filename))! s6 W( q3 G' x2 Q. ~
6 _ |- |5 x" X8 l* d% o- # print(filenames)$ L1 x% p$ n% G( t
- with open('listname.txt', encoding='utf-8', mode='r') as f:8 Q2 V0 C/ P8 N: ?6 z3 ]0 F1 u; [; _
- listnames = f.readlines()- W) Z& {* t% g9 v
- for filename in filenames:
8 Y; C# x# e8 w! t - filetype = '.mp4'2 ]) b( G5 J5 ^
- splitedfilename = filename.split('【')0 t6 c) x7 Q) E
- sfn0 = splitedfilename[0]! T+ p, |+ ^2 S5 z( L* h
- for listname in listnames:& G) c3 {4 w# `1 y. i( S
- # splitedliciwstname = listname.split(' ')
0 q/ E3 F% P1 o7 [% L# ?4 I - sln0, *sln1 = listname.split(' ')) r9 M4 \/ |+ X
- ssln1 = ''.join(sln1)
: s9 B" t6 e9 T% X. @- T& N - # sln0 = splitedlistname[0]
6 O. e+ H6 u, n& A: e8 O; A. M - # *sln1 = splitedlistname[1:]2 N# ?% q% [% b6 D! Q( ^. E
- if sfn0 == sln0:
U! p6 p1 N) { - newfilename = sfn0 + ssln1 + filetype
- ]( q' `, @) D; g$ X; l - newfilename = newfilename.replace('\n', '').strip()
: F2 t7 K! J# n8 Q4 N - newfilename = path + '\\' + newfilename+ E& O8 l8 [# W
- filename = path + '\\' + filename: M5 }/ w9 c( n
- print(os.path.isfile(filename))
. F: J: V4 u! d - print(newfilename) os.rename(filename, newfilename)
' @5 V* z; F3 ^# b; L+ v9 J 主要思路是找出原始文件名和官网上的文件名重复的部分,匹配后用官网正确的文件名替换。
; l% I: D, Y+ d$ R3 Z& Z9 G6 n( _- G R9 t) s& U
资源下载地址和密码(百度云盘): [/hide] 百度网盘信息回帖可见& v/ V3 v J5 ~; A5 ~; {/ ~
& E1 m/ l( ]# w8 u8 ?# ~& ~' A+ J
4 T$ g, X/ `- b, I1 [. |+ O5 r" T% o- T3 f0 Q
本资源由Java自学网收集整理【www.javazx.com】 |
|