-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpathClear.py
More file actions
95 lines (82 loc) · 2.7 KB
/
Copy pathpathClear.py
File metadata and controls
95 lines (82 loc) · 2.7 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
from os import listdir, mkdir, path
import shutil
class PathClear:
val_path = ''
options_path = ''
paths = {
'png': 'images',
'svg': 'images',
'jpeg': 'images',
'app': 'app',
'pdf': 'pdf',
'dmg': 'dmg',
'html': 'html',
'doc': 'documenti',
'zip': 'zip',
'folders': 'folders',
'all': 'shit',
}
def __init__(self, val_path: str = None, paths: dict = None) -> None:
if val_path:
self.val_path = val_path
if paths:
self.paths = paths
def path_clear(self) -> None:
def create_directory(path):
try:
mkdir(path)
except OSError:
print("Creation of the directory %s failed" % path)
else:
print("Successfully created the directory %s " % path)
for f in listdir(self.val_path):
flag = False
sub = ''
for sub_f in f:
if sub_f == '.':
sub = ''
flag = True
elif flag:
sub += sub_f
start_path = self.val_path + '/' + f
val_path = None
if sub in self.paths:
val_path = self.val_path + '/' + self.paths[sub]
elif sub != '':
val_path = self.val_path + '/shit'
elif not(f in self.paths.values()) or val_path == '':
val_path = self.val_path + '/folders'
if val_path is not None:
if not path.exists(val_path):
create_directory(val_path)
shutil.move(start_path, val_path + '/' + f)
def update_paths(self, paths: dir) -> None:
self.paths = paths
def auto_update_paths(self):
key = ''
value = ''
paths = {}
flag = True
with open(self.options_path, 'r') as f:
for line in f:
for ch in line:
if ch == ':':
flag = False
if ch == ',':
paths[key] = value
flag = True
key = ''
value = ''
elif flag and ch != ' ':
key += ch
elif ch != ':' and ch != ' ':
value += ch
self.paths = paths
def add_file_type(self, key: str, value: str) -> None:
self.paths[key] = value
def del_file_type(self, key: str) -> bool:
return self.paths.pop(key)
def print_path(self):
for val in self.paths:
print(val, end=' ')
print()