-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchange_dir.py
More file actions
57 lines (57 loc) · 1.86 KB
/
change_dir.py
File metadata and controls
57 lines (57 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import os
import re
import time
def get_list(old_list,pattern):
new_list = []
for i in old_list:
if pattern.search(i):
new_list.append(i)
return new_list
def get_new_list(old_list):
new_list = []
for i in old_list:
element_time = os.stat(i).st_mtime
difference = (time.time() - element_time)/86400
if difference >=4 :
new_list.append(i)
return new_list
def change_dir_list(old_list):
for i in old_list:
if 'The.Last.Ship' in i:
old_list.remove(i)
os.rename(i,r'H:/电影/末日孤舰/'+i)
print(i.ljust(35)+'移至H:/电影/末日孤舰')
elif 'Tyrant' in i:
old_list.remove(i)
os.rename(i,r'H:/电影/Tyrant/'+i)
print(i.ljust(35)+'移至H:/电影/Tyrant')
elif '24.S09' in i:
old_list.remove(i)
os.rename(i,r'H:/电影/24h/'+i)
print(i.ljust(35)+'移至H:/电影/24h')
elif 'The.Flash' in i:
old_list.remove(i)
os.rename(i,r'H:/电影/The Flash/'+i)
print(i.ljust(35)+'移至H:/电影/The Flash')
else:
os.rename(i,r'H:/电影/'+i)
print(i.ljust(35)+'移至H:/电影')
return old_list
def change_dir(list_dir):
pattern = re.compile(r'.*\.(mkv|mp4|rmvb|ass|srt)$')
os.chdir(list_dir)
old_list = os.listdir()
new_list = get_list(old_list,pattern)
move_list = get_new_list(new_list)
new_move_list = change_dir_list(move_list[:])
return len(move_list)
if __name__ == "__main__":
a = time.time()
b = change_dir(r'H:\迅雷下载')
dir_list = [i for i in os.listdir() if os.path.isdir(i)]
for i in dir_list:
c = change_dir('H://迅雷下载//'+i)
b = b+c
print('本次共移动%s部电影' %b)
print(time.time()-a)
input('按Enter键退出')