📄

Smart PDF Rename

Automatically rename PDF files based on their content (title, date, invoice number).

Document ⭐⭐ Intermediate ⏱️ 5 minutes

😫 The Pain Point

You downloaded 100 invoices all named “download.pdf” or “doc123.pdf”. You need them named like “Invoice_2024-01-15_CompanyName.pdf” for organized filing.

🚀 Agentic Solution

A Content-Based Renamer that reads the PDF and names it intelligently.

Key Features:

  • Pattern Matching: Extract invoice numbers, dates, titles using regex.
  • Template Naming: Define your naming format.
  • Preview Mode: See proposed names before applying.

⚔️ Phase 1: Commander (Quick Fix)

For quick renaming.

Prompt:

“I have a folder invoices with PDFs. Write a Python script using pdfplumber to:

  1. Extract: Read first page of each PDF.
  2. Find Patterns:
    • Invoice number: regex INV-\\d+ or Invoice #\\d+
    • Date: regex for common date formats
  3. Rename: To format {Invoice_Number}_{Date}.pdf
  4. Dry Run: Default to preview; --apply to actually rename.

Print proposed renames. Skip files where pattern not found.”

Result: Organized file names based on content.

🏗️ Phase 2: Architect (Permanent Tool)

For Accountants/File Managers.

Engineering Prompt:

**Role:** Python GUI Developer (PyQt6 Specialist)
**Task:** Create "Smart PDF Renamer" Desktop App

**Objective:** A batch renaming tool that extracts metadata (Invoice#, Date) from PDF content.

**Tech Stack:**
* Language: Python 3.10+
* GUI Library: PyQt6 (Cross-platform)
* Parser: pdfplumber, Regex
* Packaging: PyInstaller

**Functional Requirements:**
1.  **UI Layout (PyQt6):**
    *   **Input:** Folder Selector.
    *   **Pattern:** Regex Builder (e.g., `INV-\d+`).
    *   **Template:** Naming Schema `{RegexMatches[0]}_{Date}.pdf`.
    *   **Review:** Table showing "Current Name" -> "New Name" (Editable).
    *   **Action:** "Commit Renames".

2.  **Core Logic:**
    *   Extract text from page 1.
    *   Find matches; Dry-run to generate preview.
    *   `os.rename` with duplicate handling (append `_1`).
    *   **Threading:** Extraction loop runs in background.

3.  **Deliverables:**
    *   `main.py`: Complete source code.
    *   `requirements.txt`: Dependencies.
    *   **Build Instructions:**
        *   Windows: `pyinstaller --onefile --noconsole main.py`
        *   macOS: `pyinstaller --windowed --noconsole main.py`

🧠 Prompt Decoding

  • Dry Run: Essential for file renaming tools. Never rename without preview.

🛠️ Instructions

  1. Copy Prompt → Run with preview.
  2. Review names → Apply.

Related Workflows

Explore other categories

📬

Get Started with Agentic Working

Subscribe to receive updates from AgenticWorking.io

📖 Free eBook Guide 📦 7 Ready-to-use Scripts 🔔 Weekly Tips

No spam, unsubscribe anytime. Join 1,000+ subscribers.