I downloaded some PowerPoint slides and wmv programming videos from a college website and the original file names had spaces in them, so my browser’s downloader plugin converted the spaces to _20. I wanted to rename them so they wouldn’t have the _20 in them, and the following is the code I used to do so. Hope someone finds it useful.
import os import os.path files = os.listdir(os.getcwd()) for file in files: #if '20' and 'wmv' in file: if ' ' and 'ppt' in file: new_name = file.replace(' ', '_') print "%s %s" % (file, new_name) os.rename(file, new_name)