-
Notifications
You must be signed in to change notification settings - Fork 0
/
organizer.py
38 lines (23 loc) · 882 Bytes
/
organizer.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
from functools import reduce
from pathlib import Path
from tools import check_config_existence
def main():
import sys
frozen: bool = hasattr(sys, 'frozen')
location: Path = Path(sys.executable).parent if frozen else Path(__file__).parent
directory: str = sys.argv[1]
config: dict = check_config_existence(location=location.resolve())
for file in Path(directory).glob('*'):
if file.name not in list(config.keys()) + ['Others']:
if file.suffix.split('.')[-1] not in list(reduce(lambda x, x2: x + x2, config.values())):
others_f: Path = Path('Others')
others_f.mkdir(exist_ok=True)
file.rename(others_f.joinpath(file.name))
continue
for folder, extensions in config.items():
f: Path = Path(folder)
if file.suffix.split('.')[-1] in extensions:
f.mkdir(exist_ok=True)
file.rename(f.joinpath(file.name))
continue
main()