The standard library function os.rename(src, dst) will do the trick. This is all you need if you know what the extension should be (for example, all -.pdf files). If you have a mixed package of .doc, .pdf, .jpg, .xls files without extensions, you will need to examine the contents of the file to determine the correct extension using something like python-magic .
import os for fn in os.listdir(path='.'): os.rename(fn, fn + ".pdf")
source share