Once upon a time, I’ve been asked
“Greg, which console command would convert track filenames of the type INTERPRET_Trackname.mp3 to Interpret – Trackname.mp3 ?”
I’ve answered with a simple python script that can be found down below. It could be easily enhanced to gather data from existing id3 tags:
#! /usr/bin/env python
import sys
import os.path
import re
def visit(arg, dirname, names):
for name in names:
sn = os.path.splitext(name)
if sn[1][1:] == 'mp3':
oldName = os.path.join(dirname, name)
p = re.compile('_')
s = p.split(name)
if len(s) > 1 and s[0].isupper():
newName = os.path.join(dirname, s[0].capitalize() + ' - ' + s[1])
os.rename(oldName, newName)
print 'File "' + oldName + '" renamed to "' + newName + '".'
if len(sys.argv) > 1:
path = sys.argv[1]
else:
path = '.'
os.path.walk(path, visit, 0)
With that amount of code one wouldn’t even have collected the filenames in C.