A powerful Node.js utility that brings order to chaotic file systems by normalizing filenames and directories to follow consistent naming conventions.
- Multiple naming styles - Convert to kebab-case, snake_case, camelCase, PascalCase, or lowercase
- Recursive processing - Handles entire directory trees with a single command
- Special character handling - Replace or remove problematic characters
- Dry run mode - Preview changes before applying them
- Configurable options - Customize the behavior to suit your needs
- Smart directory handling - Processes directories in the correct order to avoid path issues
# Clone the repository
git clone https://github.com/pilot2254/filename-normalizer.git
# Navigate to the project directory
cd filename-normalizer
# Make the script executable (Unix/Linux/macOS)
chmod +x normalize-filenames.js
- Edit the configuration in
normalize-filenames.js
to set your source directory and preferences - Run in dry-run mode first to preview changes:
node normalize-filenames.js
- When satisfied with the proposed changes, set
dryRun: false
in the config and run again:
node normalize-filenames.js
The script is customizable through the config
object at the top of the file:
const config = {
// Directory to process
sourceDir: './your_directory',
// Naming style: 'snake_case', 'kebab-case', 'camelCase', 'PascalCase', 'lowercase'
namingStyle: 'kebab-case',
// Character replacements (special characters and what to replace them with)
replacements: {
'&': 'and',
'+': 'plus',
'@': 'at',
// Add your own replacements
},
// Characters to remove entirely
removeChars: ['!', '#', '%', '{', '}', '[', ']'],
// Whether to process subdirectories
recursive: true,
// Whether to actually rename files or just simulate (dry run)
dryRun: true,
// Whether to normalize directories as well as files
normalizeDirs: true,
// How to handle spaces
spaceReplacement: '-', // or '_', or ''
};
Option | Description | Default |
---|---|---|
sourceDir |
Directory to process | './test_directory' |
namingStyle |
Naming convention to apply | 'kebab-case' |
replacements |
Map of characters to replace | { '&': 'and', '+': 'plus', '@': 'at' } |
removeChars |
Characters to remove entirely | ['!', '#', '%', '{', '}', '[', ']'] |
recursive |
Process subdirectories | true |
dryRun |
Preview changes without applying | true |
normalizeDirs |
Apply to directory names | true |
spaceReplacement |
Character to replace spaces | '-' |
const config = {
sourceDir: './my_project',
namingStyle: 'kebab-case',
dryRun: false
};
const config = {
sourceDir: './src',
namingStyle: 'camelCase',
normalizeDirs: false,
dryRun: false
};
Standardize filenames for web projects to ensure consistent URLs and prevent case-sensitivity issues:
const config = {
sourceDir: './public',
namingStyle: 'kebab-case',
recursive: true
};
Clean up camera-generated filenames or inconsistent manual names:
const config = {
sourceDir: './photos',
namingStyle: 'snake_case',
replacements: {
'IMG_': '',
'DSC': '',
'DCIM': ''
}
};
Enforce consistent naming across a codebase:
const config = {
sourceDir: './src',
namingStyle: 'camelCase',
normalizeDirs: false
};
const directories = ['./photos', './documents', './music'];
directories.forEach(dir => {
config.sourceDir = dir;
normalizeFileNames();
});
You can extend the script by adding your own naming function:
// Add to the switch statement in normalizeFilename function
case 'custom':
// Your custom naming logic here
name = name.replace(/[^a-zA-Z0-9]/g, '_').toLowerCase();
// Add any other transformations
break;
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Commit your changes:
git commit -m 'Add some amazing feature'
- Push to the branch:
git push origin feature/amazing-feature
- Open a Pull Request
- Add command-line argument support
- Implement conflict resolution strategies
- Add pattern-based file exclusions
- Create an undo functionality
- Add support for custom regex patterns
This project is licensed under the MIT License - see the LICENSE file for details.