How to Rename a File in Python
You can rename a file using naive method like just going to the properties of the file and change its name. Or else you can rename a file using Python.
os.rename()
method in OS module of Python is used to rename a file or directory.
os.rename(original_name, new_name)
import os original_name = "C:/Users/user/Desktop/file1.py" new_name = "C:/Users/user/Desktop/sample.py" os.rename(original_name, new_name) print("Rename successfull")
Subscribe
Login
Please login to comment
0 Discussion