跳到正文
DEV Community· Arkaprava Bhattacharya·· 3 小時前AI 評分47

LazyRename:我用 AI 命名檔案,結果用得太多

I Used Too Much AI, So Now It Names My Files

AI 導讀

LazyRename 使用 Ollama 已安裝的模型,根據檔案內容為 PDF、TXT、MD 和 PY 檔案建議短檔名,並提供可編輯的預覽,確認後才會重新命名。它保留副檔名,檢查檔名規則和重複名稱,並以 JSON 交易記錄支援復原最近一批操作。模型在本機執行;示範使用 qwen3.5:4b,四個檔案重新命名後均成功復原。

正文

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 3: Slow and Steady

What I Built

I may have used AI too much: now I'm asking it what to call scan0004.pdf. The sample folder also has document_001.txt and notes_final_v3.md. Those names tell me almost nothing about the contents. To improve a whole folder by hand, I would have to open each file, figure out what it is, and check that the new name will not collide with something already there. That is the sort of chore I put off.

LazyRename does the reading. It scans a local folder for PDF, TXT, MD, and PY files, then asks an installed Ollama model for a short filename based on each file's contents. I get a table with the old and suggested names, and I can edit or deselect any row. The rename button stays unavailable until I check a confirmation box.

It keeps each file in its original folder and preserves its extension. It also checks Windows filename rules and collisions, writes a JSON transaction log, and offers an undo button for the latest batch. The code never executes a scanned Python file.

Demo

With qwen3.5:4b, one of the included samples was renamed like this:

Before Suggested name
scan0004.pdf quarterly-accessibility-audit-checkout-forms-labels-focus.pdf

That PDF contains a short note about checkout form labels and keyboard focus. The model did not receive scan0004.pdf in its prompt. In the same disposable-folder test, four suggestions were confirmed and renamed, then Undo restored every original name. The exact words a model suggests can vary by model and run.

This is a local desktop workflow, so there is no hosted app link. To try it, copy sample_files to a disposable folder, follow the Windows setup instructions, select that folder in LazyRename, and choose an installed Ollama model.

Code

LazyRename on GitHub is MIT licensed. The main pieces are the Streamlit interface, file handling and undo logic, and Ollama client. The repository also has sample files and tests for filename validation, collisions, encrypted PDFs, interrupted batches, and undo.

How I Built It

The app uses Python 3.11+, Streamlit for the review screen, PyMuPDF for PDF text extraction, and Ollama's local API for suggestions. The user can pick from models already installed in Ollama. The local demo used qwen3.5:4b; the setup guide also shows how to install gemma3:4b.

The model gets a bounded excerpt of the file's contents, with no original filename in the prompt. LazyRename reads up to three PDF pages or 64 KB of a text file and sends no more than 4,500 characters to Ollama. It skips empty files, encrypted PDFs, binary files, and files over 25 MB. Those limits keep a stray large file from turning a quick folder cleanup into a huge inference job.

Each model request handles one file. I later found a report of a small model mixing up names across a batch, which reinforced that choice and the need for a preview.

After inference, Python sanitizes the proposed name and keeps the original extension. Before applying a batch, it checks for collisions and verifies that the source files have not changed since the preview. The transaction log records the moves so Undo can check the paths again before restoring them. If the original name is occupied or a renamed file has changed, Undo stops instead of overwriting it.

The model can still misunderstand a file, especially when useful details fall outside the excerpt. That is why the preview is editable and every rename needs a deliberate confirmation. Image-only PDFs need OCR, which this version does not have.

Why Does Open Innovation Matter?

These files can contain private notes, code, or work documents. With Ollama, the excerpt goes to a model running on the same computer, through 127.0.0.1; it does not have to go to a paid hosted API. There is no API key, and I can switch models without rebuilding the app around one provider.

The source is open, too. Someone can inspect the extraction limits, change the prompt, add OCR, or tighten the rename checks. The app disables Streamlit usage stats and implements no telemetry. Packages and models need to be downloaded first; I have not tested a full run with network connectivity disabled, so I am not claiming an offline test result.

My Agent Session

I used an AI coding assistant while building and testing LazyRename. I have not shared the session transcript yet. If I add it, I will review it first and link it here.

The Lazy Payoff

LazyRename displays a potential saving of 30 seconds per selected file. In the four-file sample run, that showed two minutes. It is an assumption for illustrating the manual work, not a measured speedup. I have not timed the full process against hand-renaming a real folder, including model loading and reviewing suggestions.

來源:DEV Community · dev.to