Rule-based file sorting engine with pattern matching and dry run support
Project description
philiprehberger-file-organizer
Rule-based file sorting engine with pattern matching and dry run support.
Installation
pip install philiprehberger-file-organizer
Usage
from philiprehberger_file_organizer import Organizer, Rule
organizer = Organizer(
rules=[
Rule(extensions=[".pdf", ".doc", ".docx"], destination="~/Documents"),
Rule(extensions=[".jpg", ".png", ".gif"], destination="~/Pictures"),
Rule(extensions=[".mp4", ".mkv"], destination="~/Videos"),
Rule(pattern="invoice_*", destination="~/Documents/Invoices"),
]
)
# Preview what would happen (dry run)
report = organizer.preview("~/Downloads")
for action in report.actions:
print(f"{action.source} -> {action.destination}")
# Execute
report = organizer.organize("~/Downloads")
print(f"Moved {report.total_moved} files ({report.total_size} bytes)")
# Undo
restored = Organizer.undo("~/Downloads")
Rule Options
| Option | Description |
|---|---|
extensions |
Match by file extension |
pattern |
Match by glob pattern |
name_contains |
Match if filename contains string |
larger_than |
Minimum file size in bytes |
smaller_than |
Maximum file size in bytes |
older_than_days |
Match files older than N days |
newer_than_days |
Match files newer than N days |
predicate |
Custom matching function |
Conflict Resolution
organizer = Organizer(rules=rules, conflict="rename") # default: adds (1), (2)...
organizer = Organizer(rules=rules, conflict="skip") # skip existing
organizer = Organizer(rules=rules, conflict="overwrite") # overwrite existing
API
| Function / Class | Description |
|---|---|
Organizer(rules, conflict, recursive) |
Rule-based file organizer with preview(), organize(), and undo() methods |
Rule(destination, extensions, pattern, ...) |
A rule that matches files by extension, pattern, size, or age |
MoveAction |
Describes a planned or executed file move (source, destination, size) |
OrganizeReport |
Result of an organize operation with actions, skipped, errors, total_moved, total_size |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this project useful:
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file philiprehberger_file_organizer-0.1.9.tar.gz.
File metadata
- Download URL: philiprehberger_file_organizer-0.1.9.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4992ebd96082dd462c0ec29dfb28da6027b27e73505157e9a4dcce708277b344
|
|
| MD5 |
b74deabc57cb7bd5c8984285f14427d8
|
|
| BLAKE2b-256 |
0f35c7a78c1fd9ae95d671d0d05451dcccd3ee71e9f460c85cf175f79d0e46a6
|
File details
Details for the file philiprehberger_file_organizer-0.1.9-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_file_organizer-0.1.9-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48392e77b09f441d43091d3376814e9feef69ffe28a8855c220b9329a3f66aa1
|
|
| MD5 |
dc73c6094096e00a3e66e02652b2d8ae
|
|
| BLAKE2b-256 |
191ebffbb279df0ab9bc7ce7a97453cb2430e21da192db5b5fa7cbe1de4fd189
|