import os for filename in os.listdir(r'.'): print filename os.rename(filename,filename.replace(' ','_')) cmd= "avconv -i "+filename.replace(' ','_') + " ./mp3/"+ filename.replace('m4a','mp3').replace(' ','_') print cmd os.system(cmd)