Renaming Files with Python
Question: How to rename a file named a.txt to b.kml using Python?
Answer:
To rename files in Python, utilize the os.rename() function. It takes two arguments: the current file path and the desired new file path.
import os # Rename 'a.txt' to 'b.kml' os.rename('a.txt', 'b.kml')
Usage:
The syntax for os.rename() is:
os.rename('from.extension.whatever','to.another.extension')
Where:
The above is the detailed content of How to Rename a File in Python?. For more information, please follow other related articles on the PHP Chinese website!