Ok, so the function simplifyed without loops: def renamer(folder, band): archive = #file to transform rest = archive[3:] print band + " -",rest.capitalize() obs: the file names came this way(with spaces or apostrophes) from the cd i imported.