Get The Most Affordable Hosting in the World!
Starting at just $1.87/month, Vercaa offers unbeatable pricing for world-class web hosting services.
Fast, reliable, and secure hosting to power your website without breaking the bank. Plus, enjoy a free CDN for faster loading times worldwide!
Get Started Now!Python os module provides methods that help you perform file-processing operations, such as renaming and deleting files.
To use this module, you need to import it first and then you can call any related functions.
rename() Method
The rename() method takes two arguments, the current filename and the new filename.
Syntax
Example
Following is an example to rename an existing file "test1.txt" to "test2.txt" −
remove() Method
You can use the remove() method to delete files by supplying the name of the file to be deleted as the argument.
Syntax
Example
Following is an example to delete an existing file "test2.txt" −