A lightweight Python script to remove numeric prefixes from audio filenames in your music library.
Removes numeric prefixes like 001 , 042 , 123 from MP3 and M4A files:
001 Ae Dil Hai Mushkil.mp3 → Ae Dil Hai Mushkil.mp3
042 Ilahi.mp3 → Ilahi.mp3
If the non-prefixed filename already exists, the numbered version is deleted.
- Fix capitalization inconsistencies
- Normalize spacing around hyphens or special characters
- Handle other file formats (only
.mp3and.m4a) - Rename files with non-numeric prefixes
This script can permanently delete files. Always run in DRY RUN mode first.
No dependencies required. Just Python 3.6+.
git clone https://github.com/Aaryan-source/music-library-cleaner.git
cd music-library-cleanerpython music_library_cleaner.pyThis shows what would happen without making changes:
=== DRY RUN MODE (no changes will be made) ===
[RENAME] 001 Song.mp3 → Song.mp3
[DUPLICATE] Keeping: Another Song.mp3
[DUPLICATE] Removing: 042 Another Song.mp3
Scan complete.
Directory entries scanned: 245
Files renamed: 120
Duplicates removed: 3
- Open
music_library_cleaner.py - Change line 11:
DRY_RUN = False # Was True
- Run again:
python music_library_cleaner.py
- Scans the current directory for
.mp3and.m4afiles - Identifies files starting with digits followed by a space (e.g.,
^\d+) - Removes the numeric prefix
- If a conflict exists, deletes the numbered version and keeps the non-numbered one
Important: When a duplicate is detected, the script assumes the non-prefixed filename is the desired version and removes the numbered file. If you want to keep the numbered version instead, rename it manually before running the script.
Edit these constants at the top of the script:
DRY_RUN = True # Safety switch
SUPPORTED_EXTENSIONS = ('.mp3', '.m4a') # Add more if needed=== DRY RUN MODE (no changes will be made) ===
[RENAME] 001 Ae Dil Hai Mushkil -Arijit Singh.mp3 → Ae Dil Hai Mushkil -Arijit Singh.mp3
[RENAME] 003 Alec Benjamin -Let Me Down Slowly.mp3 → Alec Benjamin -Let Me Down Slowly.mp3
[DUPLICATE] Keeping: Give Me Some Sunshine -3 Idiots.mp3
[DUPLICATE] Removing: 037 Give Me Some Sunshine -3 Idiots.mp3
Scan complete.
Directory entries scanned: 245
Files renamed: 187
Duplicates removed: 5
- Dry run by default: Must explicitly disable to make changes
- Clear logging: Every action is printed before execution
- Duplicate detection: Won't overwrite existing files
- File type filtering: Only processes audio files
MIT License - feel free to use and modify.
This is a simple personal utility script, but suggestions are welcome! Open an issue or PR.
Pro tip: Always backup your music library before running any batch rename tool.