Skip to main content

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

Project description

philiprehberger-file-organizer

Tests PyPI version License

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

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.1.8.tar.gz (5.4 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.1.8.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_file_organizer-0.1.8.tar.gz
Algorithm Hash digest
SHA256 bec0e1c96bd60974792bbd01adbe700df89edb60a7bdb4baead1a2bb68e1a372
MD5 80f2521483420dea766170e7af21b64d
BLAKE2b-256 c38bf389d9fe2f0ce08bf70a50abbd387bccc76b3c820b1dc6f0a270b6b05e15

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_file_organizer-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 68b28d6fc83f4df245bbc617278b32bd08aebf23ac8ce159c1b885870e1b11a8
MD5 0aea249702a03b0162af562a70592aad
BLAKE2b-256 0ad6bee76bbc154d4ca456f8f032bee8d27fd0560ecc5e0486730f8ca50bf543

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