Skip to content

feat(ps1): auto-sort receipts into YYMM subfolders based on filename date #102

Description

@ndomako10

Summary

Add a feature to automatically move receipt files into the correct YYMM month subfolder under RECEIPTS_ROOT based on the date parsed from each filename.

Currently, the user must manually place receipts into the right folder (e.g. 2603\ for March 2026) before running a sync. A sorting step would eliminate that manual effort — drop files into an inbox folder, run the sorter, then sync.

Proposed behaviour

  • Reads receipt files from a source folder (e.g. RECEIPTS_ROOT\Inbox\ or a user-supplied path)
  • Parses each filename with the existing ConvertFrom-ReceiptFileName function
  • Moves each file to RECEIPTS_ROOT\YYMM\ (creating the folder if it does not exist)
  • Skips and warns on files that fail to parse (ParseOK = $false) — never moves an unparseable file
  • Supports a -WhatIf / dry-run mode that prints what would move without touching the filesystem
  • Reports a summary: N moved, M skipped (with reasons)

Design notes

  • Should reuse ConvertFrom-ReceiptFileName as-is — no changes to the parser needed
  • Could be implemented as:
    • A new script Scripts/Sort-Receipts.ps1 (cleaner separation, easier to test)
    • Or a -Sort switch on Sync-Receipts.ps1 that runs before the sync loop
    • A standalone script is preferred so sorting can be run independently of syncing
  • A corresponding launcher Launchers/Run-SortReceipts.bat would follow the existing launcher pattern
  • The inbox folder path should be configurable (parameter + Config.env variable, or default to RECEIPTS_ROOT\Inbox\)
  • Pester tests should cover: correct target path derivation, skipping unparseable files, -WhatIf mode, and folder creation

Files affected

  • Scripts/Sort-Receipts.ps1 — new script
  • Launchers/Run-SortReceipts.bat — new launcher
  • Config/Config.template.env — add INBOX_ROOT variable (optional)
  • README.md, CLAUDE.md — document new script and launcher
  • Tests/Sort-Receipts.Tests.ps1 — new test file (pure logic; no COM dependency)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions