A powerful Node.js script for bulk file renaming with pattern-based matching and comprehensive validation.
- Pattern-based Renaming: Automatically rename files based on configurable naming patterns
- Recursive Directory Scanning: Process entire directory trees with subdirectory support
- Comprehensive Validation: Full settings validation with specific error messages
- Flexible Configuration: Customizable target names, separators, and replacement patterns
- Safe Operation: Built-in safeguards and detailed logging
- Error Resilience: Continues processing despite individual file failures
- TypeScript: Fully typed with comprehensive type definitions
-
Clone the repository:
git clone https://github.com/orassayag/renamer.git cd renamer -
Install dependencies:
npm install # or pnpm install -
Configure settings in
src/settings/index.ts:export const SETTINGS: Settings = { targetNames: ['IMG', 'Screenshot'], replaceName: 'notes-', scanPath: 'C:\\Users\\Username\\Downloads', separator: '_', ignorePaths: ['node_modules', '.git'], sleepAfterMilliseconds: 50, };
-
Run the script:
npm start
The script renames files that match the pattern:
[targetName][separator][remainingFileName]
Example: Files like IMG_photo1.jpg become notes-photo1.jpg
Before:
├── IMG_photo1.jpg
├── Screenshot_2023.png
├── IMG_vacation.jpg
└── document.pdf
After (with targetNames: ["IMG", "Screenshot"], replaceName: "notes-"):
├── notes-photo1.jpg
├── notes-2023.png
├── notes-vacation.jpg
└── document.pdf (unchanged - doesn't match pattern)
| Parameter | Type | Description | Example |
|---|---|---|---|
targetNames |
string[] |
File prefixes to match | ["IMG", "Screenshot"] |
replaceName |
string |
New prefix for renamed files | "notes-" |
scanPath |
string |
Directory to scan | "C:\\Users\\Username\\Downloads" |
separator |
string |
Single character separator | "_" |
ignorePaths |
string[] |
Directories to skip | ["node_modules", ".git"] |
sleepAfterMilliseconds |
number |
Delay between operations | 50 |
- INSTRUCTIONS.md: Comprehensive usage guide and configuration details
- Type Definitions: Full TypeScript support with
src/types/settings.ts - Code Documentation: Inline JSDoc comments throughout the codebase
# Run the rename script
npm start
# Lint the codebase
npm run lintsrc/
├── logic/
│ ├── processFile.ts # Individual file processing logic
│ ├── scanAndRenameFiles.ts # Directory scanning and recursion
│ └── validateSettings.ts # Comprehensive settings validation
├── scripts/
│ └── renameScript.ts # Main execution script
├── settings/
│ └── index.ts # Configuration settings
├── types/
│ ├── settings.ts # TypeScript type definitions
│ └── index.ts # Type exports
└── utils/
├── shouldIgnorePath.ts # Path filtering utilities
├── sleep.ts # Async delay utility
└── index.ts # Utility exports
- Pre-execution Validation: All settings validated before processing
- Detailed Logging: Comprehensive operation logs and error reporting
- Error Resilience: Continues processing despite individual file failures
- Path Sanitization: Prevents path traversal vulnerabilities
- Configurable Delays: Prevents file system overload
- Backup First: Always backup important directories before bulk operations
- Test Small: Test with a small directory before processing large volumes
- No Undo: The script doesn't provide undo functionality - keep backups!
- Pattern Matching: Only processes files matching the exact naming pattern
- "Cannot access scanPath": Verify the directory exists and you have read permissions
- "No files renamed": Check that your target names and separators match existing files
- "Permission denied": Ensure you have write permissions in the target directory
The script provides specific error messages for common issues:
- Invalid settings with detailed parameter validation
- File system access problems
- Type checking errors
- Path validation failures
MIT License - see LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
file- File operations and managementfiles- Multiple file processingrename- Bulk renaming functionalitybulk- Batch processing capabilities
⚡ Fast, Safe, and Reliable Bulk File Renaming