forked from HypoX64/DeepMosaics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean_cache.py
50 lines (44 loc) · 1.33 KB
/
clean_cache.py
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
import os
import shutil
def findalldir(rootdir):
dir_list = []
for root,dirs,files in os.walk(rootdir):
for dir in dirs:
dir_list.append(os.path.join(root,dir))
return(dir_list)
def Traversal(filedir):
file_list=[]
dir_list = []
for root,dirs,files in os.walk(filedir):
for file in files:
file_list.append(os.path.join(root,file))
for dir in dirs:
dir_list.append(os.path.join(root,dir))
Traversal(dir)
return file_list,dir_list
def is_img(path):
ext = os.path.splitext(path)[1]
ext = ext.lower()
if ext in ['.jpg','.png','.jpeg','.bmp']:
return True
else:
return False
def is_video(path):
ext = os.path.splitext(path)[1]
ext = ext.lower()
if ext in ['.mp4','.flv','.avi','.mov','.mkv','.wmv','.rmvb']:
return True
else:
return False
file_list,dir_list = Traversal('./')
for file in file_list:
if ('tmp' in file) | ('pth' in file)|('pycache' in file) | is_video(file) | is_img(file):
if os.path.exists(file):
if 'imgs' not in file:
os.remove(file)
print('remove file:',file)
for dir in dir_list:
if ('tmp'in dir)|('pycache'in dir):
if os.path.exists(dir):
shutil.rmtree(dir)
print('remove dir:',dir)