-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorganize.py
More file actions
41 lines (32 loc) · 1.14 KB
/
organize.py
File metadata and controls
41 lines (32 loc) · 1.14 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
import os
from pathlib import Path
SUBDIRECTORIES = {
"DOCUMENTS": ['.pdf', '.rtf', '.txt', '.docx', '.csv'],
"AUDIO": ['.m4a', '.m4b', '.mp3'],
"VIDEOS": ['.mov', '.avi', '.mp4'],
"IMAGES": ['.jpg', '.jpeg', '.png'],
"EXCECUTABLES": ['.exe', '.zip', '.msi', '.gz'],
"CODE": ['.java', '.cs', '.go', '.cpp'],
"WEB": ['.html', '.css', '.js', '.ts']
}
def pickDirectory(value):
for category, suffixes in SUBDIRECTORIES.items():
for suffix in suffixes:
if suffix == value:
return category
return 'MISC'
def organizeDirectory():
script_name = os.path.basename(__file__) # Get script's filename
for item in os.scandir():
if item.is_dir():
continue
filePath = Path(item)
filetype = filePath.suffix.lower()
directory = pickDirectory(filetype)
directoryPath = Path(directory)
if directoryPath.is_dir() != True:
directoryPath.mkdir()
# Check filename before renaming (exclude script)
if filePath.name != script_name:
filePath.rename(directoryPath.joinpath(filePath))
organizeDirectory()