Skip to main content

Rule-based file sorting engine with pattern matching and dry run support

Project description

philiprehberger-file-organizer

Tests PyPI version Last updated

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

Move Hooks

Register callbacks that fire after each successful move. Useful for logging, checksums, notifications, or kicking off downstream pipelines without subclassing.

organizer = Organizer(rules=rules)

@organizer.on_move
def log_move(action, rule):
    print(f"moved {action.source.name} -> {action.destination} (rule #{action.rule_index})")

Hooks fire only on organize() (not preview()), and only after the file has actually moved. Hook exceptions are captured in report.errors.

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
Organizer.on_move(hook) Register a (action, rule) -> None callback fired after each successful move
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:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

philiprehberger_file_organizer-0.2.0.tar.gz (188.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file philiprehberger_file_organizer-0.2.0.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_file_organizer-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f6bbab163e41b06c55fc95bd759070338ba79df5cb1348119c643d6a2f2e4476
MD5 f56f91aa3057b6135f964a9bc6507b80
BLAKE2b-256 4e0fc66b31892abb7167f077e3899c5e8a3d2ed1bee40d3da5c9e86f019b6baf

See more details on using hashes here.

File details

Details for the file philiprehberger_file_organizer-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_file_organizer-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 89eaf4835fa9251098359b6818367b16653ef4af65021e9c4bf4c62d80c8b5e0
MD5 98e371331b88e4dce09d8257bb7c2840
BLAKE2b-256 b270193999295d45e1ee141a88727823bdf7933cfab26743caecc63410fccf94

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page