-
Notifications
You must be signed in to change notification settings - Fork 0
/
dir_org.py
36 lines (31 loc) · 1018 Bytes
/
dir_org.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
import os
import logging as log
from pathlib import Path
BASE_DIR = 'dir_org'
SUBDIRS = {
"docs": 'pdf rtf txt docx pptx xlsx',
"audio": 'm4a m4b mp3 ogg wav',
"video": 'avi mpg mp4 m4v',
"image": 'jpg jpeg png gif',
"code": 'py js ts jsx tsx'
}
# config logger, only succeeds if never called before
# log.basicConfig(level=log.DEBUG)
log.basicConfig(level=log.DEBUG, filename='dir_org.log', filemode='w')
def chooseDir(val):
for category, suffixes in SUBDIRS.items():
if val in suffixes.split(): return category
return 'misc'
def organizeDir():
for item in os.scandir():
origPath = Path(item)
if origPath.is_dir(): continue
suffix = origPath.suffix[1:].lower() # remove '.'
dir = chooseDir(suffix)
log.info(f'{dir}, {origPath}')
dirPath = BASE_DIR / Path(dir)
if not dirPath.is_dir():
dirPath.mkdir(parents=True)
# origPath.rename(dirPath / origPath)
if __name__ == '__main__':
organizeDir()