Sloth Sort 以本機 Gemma 3 4B 整理 Downloads 資料夾
Sloth Sort — a local Gemma 3 tidies my Downloads folder while I do nothing
Gabby Gill 開發的 Sloth Sort 透過 Ollama 在本機執行 Gemma 3 4B,為 Downloads 資料夾中的檔案建議分類、易讀檔名和文件日期。安裝程式、壓縮檔、音訊/影片及螢幕截圖按規則分類;整理前可檢視及修改方案,檔案不會被刪除或覆寫,並可復原。作者表示曾用它整理自己的 143 個檔案,並在執行前修改了 9 項建議。
This is a submission for the Hacktoberfest Open-Source AI Challenge Week 3: Slow and Steady
What I Built
My Downloads folder is where files go to be forgotten: document(7).pdf, download.pdf, Untitled document.docx, scan0001.jpg. Every few months I promise myself I'll sort it. I never do.
Sloth Sort sorts it for me. It reads each file on my own computer, and a local open-weight model (Gemma 3 4B via Ollama) decides what the file actually is:
-
document(7).pdf→Bills & Receipts/2026-10-14 Chinook Mobile Monthly Bill.pdf -
Untitled document.docx→Home & Car/2026-11-01 Rental Lease Agreement.docx -
download.pdf→Medical/2026-10-02 Bow River Medical Laboratory.pdf🔒 Installers, zips, audio/video and screenshots are filed by simple rules, with no AI needed. Everything else gets a folder, a readable name and the document's real date.
Who gets to be lazier? Anyone whose Downloads folder is a junk drawer: students, freelancers, parents juggling school forms, and the person who becomes the family's "computer person" every time someone can't find a document.
The whole effort is two clicks: Look through it, then Tidy. In between you can go make tea.
Being lazy shouldn't mean being reckless, so:
- Nothing moves until you've seen the plan. You can untick a file, rename it or change its folder first.
-
It never deletes and never overwrites. Name clashes become
(2),(3). - Every tidy-up has an Undo button that puts every file back under its original name.
-
It skips files that are still downloading (
.crdownload,.part) and anything changed in the last two minutes.
Demo
Try it: download slothsort-win-x64.zip (or the macOS/Linux build) from Releases, install Ollama, run ollama pull gemma3:4b, and double-click slothsort. Your browser opens with your Downloads folder already filled in. Click Look through it; nothing moves until you click Tidy.
Watch the real model work: every push re-runs the messy-folder test with Gemma 3 in GitHub Actions. The run summary shows each file, the folder and name Gemma chose, and the score.
Code
Sloth Sort 🦥
A local AI tidies your messy Downloads folder while you do nothing.
document(7).pdf becomes Bills & Receipts/2026-10-14 Chinook Mobile Bill.pdf. Untitled document.docx becomes Home & Car/2026-11-01 Rental Lease Agreement.docx. Installers, zips and screenshots get filed too. It takes two clicks: Look through it, then Tidy.
- Reads your files locally. It pulls a short text excerpt from PDFs, Word, Excel, PowerPoint, text and HTML files (and, if you turn it on, looks at photos). A local open-weight model, Gemma 3 4B via Ollama, decides the folder, a human-friendly name and the document's date.
- Rules first, AI second. Installers, archives, audio/video and screenshots are sorted by rules instantly, with no AI needed.
- Shows you the plan before anything moves. Untick files, rename them or change their folder, or just click Tidy.
- Never deletes, never overwrites. Every change is a move, recorded in…
How I Built It
Stack: .NET 8 (an ASP.NET Core minimal API) serving one offline HTML page, with Ollama running Gemma 3 4B. It uses zero third-party NuGet packages. That matters for a tool that's allowed to move your files around.
Reading files without libraries. The model can only sort what it can read, so Sloth Sort pulls a short excerpt (up to 1,500 characters) from each file:
-
PDFs: inflates the compressed content streams with .NET's built-in
ZLibStreamand collects the text-drawing operators. If the result looks like garbage, it's dropped and Sloth Sort falls back to the file name. -
Word, Excel and PowerPoint files: these are zip files of XML, so it reads them with
ZipArchiveand a hardenedXmlReader(DTDs off). - Text and HTML files: read directly, with tags stripped.
-
Photos: optional; the image itself goes to Gemma's vision input, so a photographed receipt can land in Bills & Receipts instead of Photos.
Asking the model for a decision, not a conversation. Each file goes to Ollama's
/api/chatwith a JSON schema informat. The model must answer with afolderfrom a fixed list, a shorttitleand adate. Temperature is 0. The prompt says "do not invent": with no clear date, the file's own date is used.
One thing I moved out of the model: I first asked Gemma to flag "sensitive" files, and it flagged 10 of 11, which makes a warning useless. Now the 🔒 simply comes from the folder (Banking & Taxes, Medical, IDs & Personal). It's predictable, and it's one less thing to ask a 4B model.
C# does the risky parts, not the model. The model never chooses a path. C# builds the name (yyyy-MM-dd Title.ext), removes characters Windows doesn't allow, avoids reserved names like CON, rejects dates that are impossible or more than two years ahead, and adds (2) instead of overwriting. Moves are recorded in a journal, so undo works even after you restart the app.
Guard rails. The app only tidies folders inside your user folder. It refuses your whole user folder, AppData/Library/.ssh, and system folders, and it only touches the top level. The page is served on 127.0.0.1, rejects other host names (to block DNS-rebinding tricks), and needs a custom header for every change, so another website in your browser can't trigger a tidy-up.
Tests. There are 31 built-in self-tests covering names, dates, skip rules, PDF and Word reading, the folder guard, never-overwrite, and undo surviving a restart. On every push, GitHub Actions runs them on Windows, macOS and Linux. It then installs Ollama, pulls gemma3:4b, generates a messy folder of 16 clearly-labelled fictional files, and has the real model plan the tidy-up. Each file is scored on "right folder?" and "sensible name?":
| Result | |
|---|---|
| Right folder | 15 / 15 |
| Sensible new name | 10 / 10 |
Half-finished .crdownload skipped |
yes |
| Files the dry run moved | 0 |
| Before | After (chosen by Gemma 3 4B) |
|---|---|
statement_0923.pdf |
Banking & Taxes/2026-09-01 Prairie Credit Union Chequing Statement.pdf 🔒 |
notes.txt |
School/2026-11-02 COMP 2510 Assignment 3.txt |
scan0001.jpg (a receipt photo) |
Bills & Receipts/2026-10-05 Chinook Coffee House Receipt.jpg |
booking-confirmation.html |
Travel/2026-11-20 Aurora Air Booking Confirmation.html |
To be fair to the model and to you: sixteen tidy test files are easier than a real Downloads folder. That's why the plan is always shown first, and every tidy-up can be undone.
Why Does Open Innovation Matter?
A Downloads folder is the most private place on a computer. Mine has bank statements, a lease with my address, lab results, my ID scan and my résumé. To sort those files, a model has to read them.
With a closed API, every one of those files would leave my laptop to be sorted. With an open-weight model, Gemma reads them on my machine, and the files never go anywhere. That isn't a policy promise; it's how the app is built. You can unplug the network cable and it still works.
Open weights also changed what was worth building:
- Cost: a cloud API charges per file. Sloth Sort tidying 2,000 files costs the same as tidying 20: nothing. That makes "tidy my Downloads every night" a reasonable thing to schedule.
-
Running it unattended:
slothsort tidy ~/Downloads --yescan run from Task Scheduler. There's no API key to expire and no rate limit to hit at 3 a.m. -
Yours to change: swap in
gemma3:12borqwen2.5vl:7bwith one flag, edit the folder list or the prompt, or add rules. The code is MIT; the model's terms are Gemma's. Open source also means you can check that a tool which moves your files around does what it says. Every move, and every undo, happens in one short C# file (Engine.cs) that anyone can read.
The Lazy Payoff
This challenge rewards laziness, so here's the honest accounting.
My effort: 2 clicks. Look through it, then Tidy. That's zero decisions if I trust the plan, or a few seconds per file if I want to fix one. On a schedule (slothsort tidy ~/Downloads --yes), it's zero clicks. I ran it on my Downloads folder this week: 143 files, and I changed 9 suggestions before clicking Tidy.
The machine's effort: slow, and that's fine. On a CPU-only GitHub runner with no GPU, Gemma 3 4B takes about 31 seconds per file it has to read. The 4 rule-sorted files are instant. So the sample folder took roughly 6 minutes. That's slower than me sorting a single file. But I'm not the one waiting: I'm making tea. Slow and steady, and none of it on my time.
By hand, it's the part I never actually do. Each file means opening it, working out what it is, finding the date, typing a name and dragging it somewhere. At a rough 30 seconds a file, that's about 8 minutes for the 16-file test folder, and a whole afternoon for a real one with hundreds of files. That's why my Downloads folder has never been sorted.
The payoff that matters: a year from now, when I need last October's phone bill, I can search Chinook in Bills & Receipts instead of opening document(1).pdf through document(7).pdf one by one.
Prize Categories
Best Use of Gemma. Gemma 3 4B runs locally through Ollama and does all of the understanding: it reads text excerpts and, optionally, photos through its vision input. A GitHub Actions job runs the real model against a test folder on every push.
來源:DEV Community · dev.to

