Just like in the title, instead of renaming the files in the "target folder" it just renames all possible files in the python directory, and im not sure how to fix it, although this is my best attempt.
#!usr/local/bin/python
import re, os
from os.path import join as pjoin
targetfolder = raw_input('enter a target folder:\n').strip()
newname = raw_input('enter a new base name:\n')
newname = pjoin(targetfolder, newname)
rxin = raw_input('enter a ragex to search for:\n')
foo = re.compile(rxin)
newname = raw_input('enter a new base name:\n')
a = 0
for fname in os.listdir(os.getcwd()):
allowed_name = re.compile(rxin).match
if allowed_name(fname):
# newfname = string.lower(re.sub(foo,
# '', fname))
# b = (newname + str(a))
a += 1
c = os.path.splitext(fname)
b = (newname + str(a) + c[1])
os.rename(fname, b)