from glob import glob from shutil import copyfile from string import replace for f in glob('SVMWeights/*.xml'): nf = replace(f, 'CERT', 'FACS_') nf = replace(nf, 'Weights_', '') copyfile(f,nf)