Personally, I'd use CK Rename for batch file renaming. But in a python script, you would need something like:
Code:
import os
import re
oldstring = 'whatever'
newstring = 'new'
name_match = re.compile(oldstring)
os.chdir('target')
print 'preop:'
print os.listdir('.')
for f in os.listdir('.'):
os.rename(f, name_match.sub(newstring, f, count=1))
print 'postop:'
print os.listdir('.')
Make sure to replace 'target' with the directory containing the files.
Alternatively without much extraneous bits:
Code:
import os
import re
name_match = re.compile('whatever')
os.chdir('target')
for f in os.listdir('.'):
os.rename(f, name_match.sub('new', f, count=1))
reference:
http://docs.python.org/lib/os-file-dir.html