Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c1b5394

Browse files
Merge pull request #299 from Stonebanks-js/master
Support Custom Folder Configuration for File Arrangement in "Arrange It"
2 parents db40916 + 6db7238 commit c1b5394

File tree

4 files changed

+67
-39
lines changed

4 files changed

+67
-39
lines changed

‎.gitignore‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ node_modules/
2727
creds.js
2828

2929
# Private Files
30-
*.json
3130
*.csv
3231
*.csv.gz
3332
*.tsv

‎Arrange It/README.md‎

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,41 @@
11
# Arrange It
22

3-
With the help of this script, files can be moved automatically to the folder that corresponds to their extension (for example, ".jpg" or ".png" ==> "/Pictures," and ".mp4" ==> "/Videos").
3+
With the help of this script, files can be moved automatically to the folder that corresponds to their extension (for example, .jpg or .png files go to the /Pictures folder, and .mp4 files go to /Videos).
44

5-
## How To Run
5+
## New Feature: Custom Folder Configuration
66

7-
- Put in Download Folder Or Wherever You want to automatically move the file and Just run
7+
-Now, you can customize how files are arranged by defining your own folder structure and file extensions using a config.json file. This allows for more flexibility without needing to modify the Python code itself.
8+
python arrangeit.py
9+
10+
# How To Use the config.json File
11+
12+
1. The config.json file contains the mappings of file extensions to folder names.
13+
2. You can modify, add, or remove folder categories and file extensions as per your needs.
14+
15+
Example config.json:
16+
17+
{
18+
"Programming Files": ["ipynb", "py", "java", "cs", "js"],
19+
"Music": ["mp3", "wav", "aac"],
20+
"Videos": ["mp4", "mkv", "avi"],
21+
"Pictures": ["jpeg", "png", "gif"],
22+
"Documents": ["pdf", "docx", "xlsx"]
23+
}
824

9-
For CLI
25+
# How To Run
26+
27+
Put the script and the config.json file in the folder where you want to automatically move the files.
28+
29+
Run the following command from the terminal:
1030

11-
```bash
1231
python arrangeit.py
1332

14-
<!-- This is a manual change to ensure the file is tracked and updated -->
15-
```
1633

17-
<!-- Updated README links and corrected typos -->
18-
<!-- Updated README links and corrected typos -->
34+
The script will create folders and move files based on the folder-extension mappings in the config.json file.
35+
36+
37+
# Benefits
38+
39+
Customizable: Easily modify the config.json file to tailor the organization to your preferences.
40+
User-Friendly: No need to modify Python code—just update the config.json file.
41+
Scalable: Works with different folder structures for different use cases.

‎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

‎Arrange It/config.json‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"Programming Files": ["ipynb", "py", "java", "cs", "js", "vsix", "jar", "cc", "ccc", "html", "xml", "kt"],
3+
"Music": ["mp3", "wav", "wma", "mpa", "ram", "ra", "aac", "aif", "m4a", "tsa"],
4+
"Videos": ["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"],
5+
"Pictures": ["jpeg", "jpg", "png", "gif", "tiff", "raw", "webp", "jfif", "ico", "psd", "svg", "ai"],
6+
"Applications": ["exe", "msi", "deb", "rpm"],
7+
"Compressed": ["zip", "rar", "arj", "gz", "sit", "sitx", "sea", "ace", "bz2", "7z"],
8+
"Documents": ["txt", "pdf", "doc", "xlsx", "ppt", "pps", "docx", "pptx"],
9+
"Other": []
10+
}
11+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /