-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
150 lines (100 loc) · 3.6 KB
/
main.py
File metadata and controls
150 lines (100 loc) · 3.6 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import sys
import shutil
import scan
import normalize
from pathlib import Path
from files_generator import file_generator
def hande_file(path, root_folder, dist):
target_folder = root_folder / dist
target_folder.mkdir(exist_ok=True)
path.replace(target_folder / normalize.normalize(path.name))
def handle_archive(path, root_folder, dist):
target_folder = root_folder / dist
target_folder.mkdir(exist_ok=True)
new_name = normalize.normalize(path.name.replace('.zip', ''))
new_name = normalize.normalize(path.name.replace('.gz', ''))
new_name = normalize.normalize(path.name.replace('.rar', ''))
new_name = normalize.normalize(path.name.replace('.tar', ''))
archive_folder = root_folder / new_name
archive_folder.mkdir(exist_ok=True)
try:
shutil.unpack_archive(str(path.resolve()), str(path.resolve()))
except FileNotFoundError:
archive_folder.rmdir()
return
except shutil.ReadError:
archive_folder.rmdir()
return
path.unlink()
def remove_empty_folders(path):
for item in path.iterdir():
if item.is_dir():
remove_empty_folders(item)
try:
item.rmdir()
except OSError:
pass
def get_folder_objects(root_path):
for folder in root_path.iterdir():
if folder.is_dir():
remove_empty_folders(folder)
try:
folder.rmdir()
except OSError:
pass
def main(folder_path):
scan.scan(folder_path)
for file in scan.jpeg_files:
hande_file(file, folder_path, "images")
for file in scan.jpg_files:
hande_file(file, folder_path, "images")
for file in scan.png_files:
hande_file(file, folder_path, "images")
for file in scan.svg_files:
hande_file(file, folder_path, "images")
for file in scan.gif_files:
hande_file(file, folder_path, "images")
for file in scan.bmp_files:
hande_file(file, folder_path, "images")
for file in scan.tif_files:
hande_file(file, folder_path, "images")
for file in scan.tiff_files:
hande_file(file, folder_path, "images")
for file in scan.txt_files:
hande_file(file, folder_path, "documents")
for file in scan.docx_files:
hande_file(file, folder_path, "documents")
for file in scan.doc_files:
hande_file(file, folder_path, "documents")
for file in scan.pdf_files:
hande_file(file, folder_path, "documents")
for file in scan.xlsx_files:
hande_file(file, folder_path, "documents")
for file in scan.pptx_files:
hande_file(file, folder_path, "documents")
for file in scan.mp3_files:
hande_file(file, folder_path, "audio")
for file in scan.ogg_files:
hande_file(file, folder_path, "audio")
for file in scan.wav_files:
hande_file(file, folder_path, "audio")
for file in scan.amr_files:
hande_file(file, folder_path, "audio")
for file in scan.avi_files:
hande_file(file, folder_path, "video")
for file in scan.mp4_files:
hande_file(file, folder_path, "video")
for file in scan.mov_files:
hande_file(file, folder_path, "video")
for file in scan.mkv_files:
hande_file(file, folder_path, "video")
for file in scan.others:
hande_file(file, folder_path, "OTHERS")
for file in scan.archives:
hande_file(file, folder_path, "archives")
get_folder_objects(folder_path)
if __name__ == '__main__':
path = sys.argv[1]
print(f"Start in {path}")
arg = Path(path)
main(arg.resolve())