-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
64 lines (47 loc) · 2.13 KB
/
main.py
File metadata and controls
64 lines (47 loc) · 2.13 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
58
59
60
61
62
63
#Viewing Libraries
# Docs: PyMuPDF | Audio/Video: MoviePy | Image: Pillow | Compressed/Install: Display the name
import os
import collections
from pprint import pprint
import PyMuPDF
import MoviePy
import Pillow
audio = ['mp3', 'wav', 'raw', 'wma', 'mid', 'midi']
video = ['mp4', 'mpg', 'mpeg', 'avi', 'mov', 'flv', 'mkv', 'mwv', 'm4v', 'h264']
image = ['png', 'jpg', 'jpeg', 'gif', 'svg', 'bmp', 'psd', 'svg', 'tiff', 'tif']
docs = ['txt', 'pdf', 'csv', 'xls', 'xlsx', 'ods', 'doc', 'docx', 'html', 'odt', 'tex', 'ppt', 'pptx', 'log']
compressed = ['zip', 'z', '7z', 'rar', 'tar', 'gz', 'rpm', 'pkg', 'deb']
install = ['dmg', 'exe', 'iso']
BASE_PATH = os.path.expanduser('~')
DEST_DIRS = ['Music', 'Movies', 'Pictures', 'Documents', 'Applications', 'Other', ]
for d in DEST_DIRS:
dir_path = os.path.join(BASE_PATH, d)
if not os.path.isdir(dir_path):
os.mkdir(dir_path)
DOWNLOADS_PATH = os.path.join(BASE_PATH, 'Downloads')
files_mapping = collections.defaultdict(list)
files_list = os.listdir(DOWNLOADS_PATH)
for file_name in files_list:
if file_name[0] != '.':
file_ext = file_name.split('.')[-1]
files_mapping[file_ext].append(file_name)
pprint(files_mapping)
for f_ext, f_list in files_mapping.items():
if f_ext in install:
for file in f_list:
os.rename(os.path.join(DOWNLOADS_PATH, file), os.path.join(BASE_PATH, 'Applications', file))
elif f_ext in audio:
for file in f_list:
os.rename(os.path.join(DOWNLOADS_PATH, file), os.path.join(BASE_PATH, 'Music', file))
elif f_ext in video:
for file in f_list:
os.rename(os.path.join(DOWNLOADS_PATH, file), os.path.join(BASE_PATH, 'Movies', file))
elif f_ext in image:
for file in f_list:
os.rename(os.path.join(DOWNLOADS_PATH, file), os.path.join(BASE_PATH, 'Pictures', file))
elif f_ext in docs:
for file in f_list:
os.rename(os.path.join(DOWNLOADS_PATH, file), os.path.join(BASE_PATH, 'Documents', file))
elif f_ext in compressed:
for file in f_list:
os.rename(os.path.join(DOWNLOADS_PATH, file), os.path.join(BASE_PATH, 'Other', file))