Effortlessly rename files using local AI - No tokens, No API, No cost!
A dead-simple Python script that uses Ollama to automatically rename your files based on their content. Perfect for developers, writers, and anyone drowning in messy file names.
- Free: 100% local AI, no external services
- Simple: Just run
python rename_files.py path\to\folder
- Smart: AI understands your file content
- Safe: Original files saved in
backup_<timestamp>/
directory - Fast: Works with hundreds of files quickly-ish, with optional parallel processing
- Configurable: Interactively choose directory, file pattern, model from ollama api, and context length
- Robust: Error handling and comprehensive logging
- Python 3.8+
- Ollama (Free, local AI)
# Clone the repository
git clone https://github.com/octrow/ollama-rename-files.git
cd ollama-rename-files
# Install dependencies
pip install -r requirements.txt
# Pull a small language model (optional, the script will prompt you to choose)
ollama pull qwen2.5-coder:7b
python rename_files.py
# Rename files in specific directory
python rename_files.py -d "C:\path\to\your\folder"
# Specify path, model and context length
python rename_files.py -d "your_folder" -m "qwen2.5-coder:7b" -c 500
# CLI with directory and file pattern (no prompts)
python rename_files.py -a -d "your_folder" --prefix "new" --ext ".txt"
# Parallel processing (rename 4 files at a time)
python rename_files.py -d "your_folder" -p 4
Here's a breakdown of all the available options:
Option | Short Option | Description |
---|---|---|
--auto |
-a |
Run in auto mode without interactive prompts. Requires -d , --prefix , and --ext to be specified. |
--directory |
-d |
Specify the directory containing the files to rename. |
--model |
-m |
Specify the Ollama model to use from local ollama list. |
--context |
-c |
Specify the context length (number of characters) to send to the model based on model. |
--prefix |
Specify the file prefix to match. Used with --ext to define the file pattern. |
|
--ext |
Specify the file extension to match (including the dot). Used with --prefix to define the file pattern. |
|
--parallel |
-p |
Number of parallel rename operations. 0 (default) means sequential processing. |
- Try to run
python rename_files.py
, answer the questions! - Optionally, prompts for directory, file pattern (prefix and extension), and Ollama model.
- Finds files matching the specified pattern.
- Creates a backup directory named backup_.
- Backs up each file to the backup directory.
- Uses local Ollama AI to read file content (up to the specified context length).
- Generates a smart, descriptive filename based on the content.
- Renames the file.
- Logs every action.
Creates filenames like:
task-fix-backend-resolve-database-connection-issue.txt
doc-update-project-architecture-notes.md
- Original files are backed up before renaming.
- Comprehensive logging
- Error-resistant design with detailed error messages.
- Works with hundreds of files, sequentially or in parallel.
Found a bug? Want a feature? Pull requests are welcome!