AI-powered file sorting for local folders using Ollama.
SnapSort reads each file name plus a short text preview, asks a local Ollama model to choose a category, and then moves or copies the file into the matching folder. Files that cannot be classified safely are sent to SKIP.
- Fixed the file-sorting flow so each file is classified independently.
- Added
--thoughtto print the model's thought/decision text when the model exposes it. - Added persistent log files so users can inspect failures and model decisions after a run.
- Improved error handling for unreadable files, invalid model responses, and destination name collisions.
- Python 3.10+
- Ollama installed and running locally
- A downloaded Ollama model, for example:
ollama pull llama3.2pip install -r requirements.txtpython snapsort.py <target_folder> <ollama_model> --categories <category1> <category2> [options]Example:
python snapsort.py "C:\Downloads" "llama3.2" --categories PDFs Docs ImagesCopy instead of move:
python snapsort.py "C:\Downloads" "llama3.2" --categories PDFs Docs Images --copyShow model thought output:
python snapsort.py "C:\Downloads" "llama3.2" --categories Work Personal Archive --thoughtWrite logs to a custom location:
python snapsort.py "C:\Downloads" "llama3.2" --categories Work Personal --log-file "C:\temp\snapsort.log"--categories: Required list of allowed output folders.--output: Optional base output folder. Defaults to the target folder.--copy: Copy files instead of moving them.--thought: Print the model's thought/decision text when available.--log-file: Write logs to a specific file. By default SnapSort writes logs to<target>\logs\.
Every run writes a timestamped log file unless --log-file is provided.
Default location:
<target folder>\logs\snapsort-YYYYMMDD-HHMMSS.log
The log contains:
- startup configuration
- classification attempts
- model responses
- move/copy results
- full error traces when something fails
- SnapSort scans the top-level files in the target folder.
- It sends the file name and up to 400 characters of text preview to Ollama.
- The model must answer with exactly one allowed category or
SKIP. - SnapSort moves or copies the file into the chosen folder.
- Errors are logged and problematic files fall back to
SKIPwhen possible.
- Binary or unreadable files are classified by filename plus a fallback preview message.
- If a destination file already exists, SnapSort creates a unique name instead of overwriting it.
- Thought output depends on the model or Ollama response format. If unavailable, SnapSort prints a fallback message.
The included build.bat builds a standalone executable with Nuitka:
build.batMIT