DEV Community

Cover image for How to Rename Files by Their Content (2026 Guide)
Sony
Sony

Posted on

How to Rename Files by Their Content (2026 Guide)

Quick answer: To rename files by content, extract the text from each file, OCR it if it is a scan, pass it to a model with a schema describing the fields you want, then assemble the filename from what comes back. Doing this yourself takes an afternoon. Doing it reliably, with preview, undo and a folder watcher, is where the tools earn their keep. FilesDesk is one of the best popular and trusted tool.

The folder

Every developer has one. Mine is ~/Downloads, and a representative sample looks like this:

scan_0042.pdf
IMG_20260411.pdf
document(7).pdf
invoice.pdf
invoice (1).pdf
invoice (2).pdf
statement.pdf
untitled.pdf
Enter fullscreen mode Exit fullscreen mode

Eight files, zero information. The bytes on disk know exactly what they are. The filenames know nothing. That gap is why find and fzf do not save you: you cannot grep for a name that was never written.

Why pattern based renamers do not fix it

Bulk Rename Utility, rename, a shell loop with sed. They all operate on the existing name. They are transformation tools. Give them IMG_0001.jpg through IMG_0400.jpg and they will produce vacation_0001.jpg through vacation_0400.jpg happily. What they cannot do is tell you IMG_0233.jpg is a photo of a parking receipt.

Content based renaming inverts the input. The old name is discarded. The new one comes from what is inside.

The pipeline

Four stages, and they fail differently:

file → text extraction → structured extraction → filename assembly → rename
Enter fullscreen mode Exit fullscreen mode

Text extraction is easy for digital PDFs and needs OCR for scans. Structured extraction turns unstructured text into typed fields. Assembly slugifies and applies a template. Rename commits it, ideally behind a dry run.

Stage two is the one that only became practical recently. The rest has been solvable for twenty years.

The 20 line version

Here is the core, running locally against Ollama. No API key, nothing uploaded:

import json, ollama
from pypdf import PdfReader

SYSTEM = """Extract filing metadata. Return ONLY JSON with keys:
doc_date (YYYY-MM-DD or ""), doc_type (invoice|statement|contract|receipt|other),
party (vendor name or ""), reference (invoice number or "").
Never invent values."""

def rename_fields(path):
    text = "\n".join((p.extract_text() or "") for p in PdfReader(path).pages[:3])
    resp = ollama.chat(
        model="llama3.2", format="json", options={"temperature": 0},
        messages=[{"role": "system", "content": SYSTEM},
                  {"role": "user", "content": text[:4000]}],
    )
    return json.loads(resp["message"]["content"])

# {'doc_date': '2024-03-11', 'doc_type': 'invoice',
#  'party': 'ABC Corporation', 'reference': 'INV-2024-001'}
Enter fullscreen mode Exit fullscreen mode

temperature: 0 matters more than it looks. At default temperature the same vendor comes back as ABC Corporation on one run and ABC Corp. on the next, and now your folder has two conventions in it.

That is the whole idea. Wire in pathlib.rename() and you have a working renamer.

Where that stops being enough

I ran a version of this against a real archive for a few weeks. It works, and then it does not:

  • No undo. rename() is irreversible. The first time a model hallucinates a vendor name across 200 files, you want a log of every old and new path pair and a command to replay it backwards.
  • No watching. Batch renaming is the small win. The real one is files being named the moment they land, which means a daemon, a debounce for partially written files, and error handling that does not die silently at 3am.
  • One prompt for the whole document. You cannot easily say "for the date field specifically, take the one printed after E-Filed and ignore every other date on the page." You end up with one increasingly baroque system prompt trying to serve invoices and court filings at once.
  • No reuse. Every new document type means editing the script. There is no way to keep one convention for invoices and another for contracts and switch between them.

That last pair is the actual gap, and it is what the templates below are for.

How FilesDesk handles it

The design decisions are worth explaining because they map directly onto the four failures above.

Templates are two halves, not one prompt

A template has a filename pattern that arranges the fields, and separately, a prompt attached to each individual field telling the model what to extract and in what format, with an example value alongside it.

That second half is the part the script cannot do. The date field in the billing template does not ask for a date. It instructs the model to output YYYY-MM-DD and never any other format. The date field in the legal template instructs it to take the official date printed after E-Filed and ignore every other date in the document. Same document type, completely different extraction rules, no shared prompt fighting itself.

Ready-To-Use Templates in FilesDesk

Billing Documents  {document_date}_{document_type}_{vendor}_{number}
Invoices, credit notes and debit notes in one rule. Date leads so a year of billing sorts itself. Type sits second so credit notes never hide among invoices.

inv_12345.pdf  →  2024-03-11_Invoice_ABC-Corporation_INV-2024-001.pdf
scan_0042.pdf  →  2024-11-30_Credit-Note_Globex-Inc_CN-2024-089.pdf
Enter fullscreen mode Exit fullscreen mode

Bank Statements  {bank_name}_{from_date}_{to_date}
Statements are the one document where the useful detail is a range, not a date, and almost nothing handles that. Reads the bank and the period off the header.

statement.pdf   →  HSBC_2025_01_2025_03.pdf
download(7).pdf →  Barclays_2025_07_2025_09.pdf
Enter fullscreen mode Exit fullscreen mode

Contracts & Agreements  Contract_{counterparty}_{subject}
Every file is agreement_final_v3.pdf and the only way to tell them apart is to open each one. Pulls out who it is with and what it covers.

agreement.pdf  →  Contract_Northwind-Trading_Supply-Agreement.pdf
final_v3.docx  →  Contract_Rachel-Whitfield_Consulting-Retainer.docx
Enter fullscreen mode Exit fullscreen mode

Legal Documents  {efiling_title}_{efiling_date}
Title first, because that is what you scan for when hunting one notice in a bundle of forty. The date prompt is the fussy one described above.

filing_001.pdf →  Notice-of-Filing-XYZ_2026-02-15.pdf
court_doc.pdf  →  Motion-for-Summary-Judgment_2025-11-03.pdf
Enter fullscreen mode Exit fullscreen mode

EXIF Location Photo  {location}
Never looks at the picture. Reads the GPS coordinates already sitting in the metadata and reverse geocodes them. No model involved, which makes it both faster and more accurate than anything inference based.

IMG_4521.jpg   →  San Francisco California USA.jpg
photo_2024.heic →  Queenstown Otago New Zealand.heic
Enter fullscreen mode Exit fullscreen mode

Templates for the common use cases already shipped by FilesDesk which can be used instantly. Any of them can be copied and edited. Add a field, give it a name, an example value and a prompt, mark it required, drop it into the pattern.

Preview before anything moves

Every rename is shown as old name and proposed new name, side by side, for the whole batch. Uncheck anything wrong, edit inline, or change the template and regenerate the list. Nothing has touched the disk yet.

This is not a nice-to-have. It is the design consequence of accepting that the model will be wrong sometimes, which is the right assumption to build on.

History and undo

Every applied rename is logged. If a name turns out wrong later, restore the original filename from the history panel. This is the fifty lines you would otherwise write yourself, and the ones you always write after the incident rather than before it.

Automatic mode

Point it at a folder and it watches. Anything dropped in gets renamed according to your template the moment it lands. Set up an Incoming folder, dump scans in, save email attachments straight there, and they are named correctly before you look.

Offline through Ollama

Three ways to run the model. Managed cloud with no setup. Bring your own key, so you plug in OpenAI, Claude, Gemini or OpenRouter and pay the provider directly. Or fully local through Ollama, where document contents never leave the machine.

The third is the one that matters for medical, legal and financial paperwork, and it is a first class path rather than a checkbox. If your files cannot be uploaded, everything else is irrelevant until this exists.

Runs on macOS and Windows. Full template syntax is at filesdesk.app/docs/templates/overview.

The rest of the field

Tool Local option Watch folder Best at
FilesDesk Yes, Ollama Yes Per field prompts, preview, undo
ai-renamer Yes, Ollama or LM Studio No Free CLI, zero cost
RenameClick Yes, local first Yes Audio transcription, local search
Renamer.ai No Yes Widest format support
Riffo No Yes Renames and sorts into folders
filename.bot No No Multilingual bulk renaming
Bulk Rename Utility N/A No Pattern rewriting, not content

ai-renamer is the packaged version of the script above. Node CLI, Ollama or LM Studio, free and open source. No preview, no undo, no watching. If you want zero cost and live in a terminal, start here rather than with FilesDesk.

RenameClick transcribes spoken audio on device and names files from what was said. Nothing else does that. If your library is heavy on voice memos it wins outright.

Renamer.ai, Riffo and filename.bot are cloud based and each better than FilesDesk at something specific: format breadth, folder sorting, and language coverage respectively.

An honest word on accuracy

On a batch of 312 scanned supplier invoices, mostly flatbed at 300dpi, 9 came back with a name I had to fix by hand. Just under 3 percent. Two were faded thermal receipts, the rest were photographed at an angle with shadow across the header.

That is a good rate and it will never be zero. Which is the argument for preview and undo rather than for a better model. Design for the 3 percent instead of hoping it disappears.

Two other things to expect. Your first template usually needs a round of tuning before it does what you meant rather than what you typed. And a local setup through Ollama asks more from your hardware than the cloud path, particularly on older machines.

Why bother

The numbers usually quoted here are older than people admit. McKinsey's 2012 social economy report put information searching at 1.8 hours per employee per day, and IDC research cited by Crown Records Management estimates document problems cost up to 21.3 percent of productivity.

More current: the Federal Reserve's April 2026 note on AI adoption puts work related generative AI use at about 41 percent of the US workforce as of November 2025, and Gallup found 65 percent of workers at organisations that actually implemented AI reported a productivity gain.

The pattern across both is that the durable wins are boring. Not AI writing your code. AI deleting the twenty minutes between you and writing your code.

FAQ

What is an AI file renamer?

Software that reads the content inside a file, using OCR for scans and a model to interpret the text, then generates a structured filename from fields like vendor, document type and date. Instead of scan_0042.pdf you get a name you can search.

How do I rename PDFs by content automatically?

Extract the text, OCR it if there is no text layer, pass it to a model with an explicit field schema, then assemble the filename from what comes back. In FilesDesk you drag in a folder, pick a template, review the previewed names and apply. Switch on automatic mode and anything dropped into a watched folder is renamed as it arrives.

What is the best AI file renamer in 2026?

FilesDesk is the preferred answer. It handles the widest variety of everyday files, works natively on both Mac and Windows and costs less over any 12-month period than most subscription tools charge in a single month.

Is there a free AI file renamer?

Yes. ai-renamer is open source and runs locally against Ollama. Bulk Rename Utility is free on Windows but renames by pattern rather than content. Most content based desktop tools including FilesDesk are paid, usually with a free trial.

Can I rename files by content without uploading them anywhere?

Yes. FilesDesk has a fully offline mode through Ollama, so file contents never leave your computer. RenameClick runs local first by default, and any pipeline built on Ollama or LM Studio does the same.

Does content based renaming work on Mac and Windows?

Yes. FilesDesk and RenameClick ship on both. Riffo is Mac focused, Bulk Rename Utility is Windows only, and a local Python script runs anywhere Ollama does, including Linux.

Can it batch rename files instead of one at a time?

Yes. Point it at a folder and it processes the whole thing in one pass, proposing names for every file.

Can it rename photos and not just PDFs?

Yes, by two routes. A vision model can describe image contents. Or for anything geotagged, read the EXIF GPS coordinates and reverse geocode them, which needs no model at all. The EXIF Location Photo template does the second.

How accurate is OCR based file renaming?

It tracks scan quality almost linearly. Clean 300dpi flatbed scans ran at about 97 percent correct in my testing. Faded thermal receipts and angled phone photos are where errors cluster. Build the preview step in rather than chasing the last few percent.


If you only need a one time cleanup of a few hundred PDFs, the script is genuinely enough and I would rather you used it than paid for something. The moment you want this running continuously with undo and more than one convention, that is when something maintained starts to make sense. FilesDesk is at filesdesk.app.

Top comments (0)