How do I change the name of some PDF file (*.pdf) to convert.pdf?
There is only one PDF file in the relevant directory.
How do I change the name of some PDF file (*.pdf) to convert.pdf?
There is only one PDF file in the relevant directory.
It seems very silly to do this in Python when you could just write mv *.pdf convert.pdf
in an sh-compatible shell (the default on most non-Windows systems) or rename *.pdf convert.pdf
in cmd (the default on Windows). But if you really want to, you can do it in two ways.
import glob, os
for name in glob.iglob('*.pdf'):
os.rename(name, 'convert.pdf')
import os
for name in os.listdir('.'):
if os.path.splitext(name)[1] == '.pdf':
os.rename(name, 'convert.pdf')