Skip to content

Commit 87a3a02

Browse files
committed
Support Custom Folder Configuration added
1 parent 5a12f82 commit 87a3a02

File tree

1 file changed

+24
-29
lines changed

1 file changed

+24
-29
lines changed

Arrange It/arrangeit.py

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,42 @@
11
from shutil import move
2-
from os import path
32
import os
4-
5-
6-
directory = {
7-
'Programming Files': set(['ipynb', 'py', 'java', 'cs', 'js', 'vsix', 'jar', 'cc', 'ccc', 'html', 'xml', 'kt']),
8-
'Music': set(['mp3', 'wav', 'wma', 'mpa', 'ram', 'ra', 'aac', 'aif', 'm4a', 'tsa']),
9-
'Videos': set(['mp4', 'webm', 'mkv', 'MPG', 'MP2', 'MPEG', 'MPE', 'MPV', 'OGG', 'M4P', 'M4V', 'WMV', 'MOV', 'QT', 'FLV', 'SWF', 'AVCHD', 'avi', 'mpg', 'mpe', 'mpeg', 'asf', 'wmv', 'mov', 'qt', 'rm']),
10-
'Pictures': set(['jpeg', 'jpg', 'png', 'gif', 'tiff', 'raw', 'webp', 'jfif', 'ico', 'psd', 'svg', 'ai']),
11-
'Applications': set(['exe', 'msi', 'deb', 'rpm']),
12-
'Compressed': set(['zip', 'rar', 'arj', 'gz', 'sit', 'sitx', 'sea', 'ace', 'bz2', '7z']),
13-
'Documents': set(['txt', 'pdf', 'doc', 'xlsx', 'pdf', 'ppt', 'pps', 'docx', 'pptx']),
14-
'Other': set([])
15-
}
16-
17-
18-
def create_folders():
19-
3+
import json
4+
5+
# Load folder-extension mappings from config.json
6+
def load_config(file='config.json'):
7+
try:
8+
with open(file, 'r') as f:
9+
return json.load(f)
10+
except FileNotFoundError:
11+
print(f"Configuration file {file} not found! Using default settings.")
12+
return {}
13+
14+
# Create folders based on config.json
15+
def create_folders(directory):
2016
for dir_ in directory:
2117
try:
2218
os.mkdir(dir_)
2319
print(f'{dir_:20} Created')
2420
except OSError:
2521
print(f'{dir_:20} Already Exists')
2622

27-
28-
def get_folder(ext):
29-
30-
for f, ex in directory.items():
31-
if ext in ex:
32-
return f
23+
# Determine which folder a file belongs to
24+
def get_folder(ext, directory):
25+
for folder, extensions in directory.items():
26+
if ext in extensions:
27+
return folder
3328
return 'Other'
3429

35-
36-
def start():
30+
# Start moving files based on their extensions
31+
def start(directory):
3732
for filename in os.listdir():
3833
if filename != __file__ and filename[0] != '.' and '.' in filename:
3934
ext = os.path.basename(filename).split('.')[-1]
40-
folder = get_folder(ext)
35+
folder = get_folder(ext, directory)
4136
if not os.path.isfile(os.path.join(folder, filename)):
4237
move(filename, folder)
4338

44-
4539
if __name__ == '__main__':
46-
create_folders()
47-
start()
40+
config = load_config() # Load configuration
41+
create_folders(config) # Create necessary folders
42+
start(config) # Start organizing files

0 commit comments

Comments
 (0)