import os def atEachDir(matchlist,dirname,fileshere): for file in fileshere: if file.endswith('.mp3'): matchlist.append(os.path.join(dirname,file)) matches=[] os.path.walk(r'/home/rlipman/music/',atEachDir,matches) for file in matches: file=file.replace(' ','\ ') file=file.replace('(','\(') file=file.replace(')','\)') file=file.replace('\'','\\\'') os.system('mp3gain -c '+file) #print file