In python, to rename a file, we can use os.rename(old_name, new_name) function. In this tutorial, we will introduce how to do and you also notice os.rename() function may fail for some reason.
Import library
import os
Rename a file
try: os.renames("file.pdf", 'file-test.pdf') except Exception as e: print(e)
Then file.pdf will be renamed to file-test.pdf.