1 import os,shutil
2 # 用于存放文件名
3 list_mv_name = []
4
5 bb ='os.sep'+'n'
6 def cqk_list(file):
7 f = open(file,'r',encoding='UTF-8')
8 contents = f.readlines()
9 f.close()
10
11 for content in contents:
12 # 判断数组中的元素是否以回车符结尾
13 if '\n' in content:
14 content = content.split(':')[1][:-1] #截取,删除末尾的回车符
15 else:
16 content = content.split(':')[1]
17 list_mv_name.append(content)
18 pass
19
20 # print(len(contents))
21 # print(list_mv_name)
22
23
24 def show_files(path, all_files,hou):
25
26 file_list = os.listdir(path)
27 for file in file_list:
28 cur_path = os.path.join(path, file)
29 if os.path.isdir(cur_path): # 判断是不是一个文件
30 show_files(cur_path, all_files,hou)
31 else:
32 filename1 = os.path.splitext(cur_path)[1] # 读取文件后缀名
33 filename0 = os.path.splitext(cur_path)[0] # 读取文件名
34 if filename1 == ".flv":
35 #定义要修改的文件
36 file_name = list_mv_name[int(path.split('\\')[-1])-1] + filename1
37 count = count + 1
38 # print(file_name)
39 file_name_path = os.path.join(path,file_name)
40 os.rename(cur_path, file_name_path) #修改文件名
41
42
43 shutil.move(file_name_path, hou)
44 pass
45
46 aa ='+os.sep+'
47
48 qian = 'E:'+os.sep+'bilibili'+os.sep+'python'
49 hou = 'E:'+os.sep+'修改后'
50 file = 'python.txt' #文件名的位置,可以去哔哩哔哩视频界面复制视频文件的名字
51
52 # 遍历出所有的文件名
53 cqk_list(file)
54
55 #打印出所有的文件名
56 # print(list_mv_name)
57
58 show_files(qian,[],hou=hou)
59
60
61 print(qian.split('\\')[-1])