-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan.py
82 lines (68 loc) · 1.78 KB
/
scan.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
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
import sys
from pathlib import Path
images = []
documents = []
audio = []
video = []
archives = []
others = list()
unknown = set()
extensions = set()
folders = list()
registered_extensions = {
"JPEG": images,
"PNG": images,
"JPG": images,
"SVG": images,
'AVI': video,
'MP4': video,
'MOV': video,
'MKV': video,
'DOC': documents,
'PDF': documents,
'XLSX': documents,
'PPTX': documents,
"TXT": documents,
"DOCX": documents,
'MP3': audio,
'OGG': audio,
'WAV': audio,
'AMR': audio,
"ZIP": archives,
'GZ': archives,
'TAR': archives
}
def get_extensions(file_name):
return Path(file_name).suffix[1:].upper()
def scan(folder):
for item in folder.iterdir():
if item.is_dir():
if item.name not in ("DOCUMENTS", "AUDIO", "VIDEO", "ARCHIVE", "IMAGES", "OTHER"):
folders.append(item)
scan(item)
continue
extension = get_extensions(file_name=item.name)
new_name = folder/item.name
if not extension:
others.append(new_name)
else:
try:
container = registered_extensions[extension]
extensions.add(extension)
container.append(new_name)
except KeyError:
unknown.add(extension)
others.append(new_name)
if __name__ == '__main__':
path = sys.argv[1]
print(f"Start in {path}")
arg = Path(path)
scan(arg)
print(f"images: {images}\n")
print(f"documents: {documents}\n")
print(f"audio: {audio}\n")
print(f"video: {video}\n")
print(f"archive: {archives}\n")
print(f"unknown: {others}\n")
print(f"All extensions: {extensions}\n")
print(f"Unknown extensions: {unknown}\n")