Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (19.9k points)

I am not able to change the name of my file using "refactor" option. Can i do it by writing a script or is there any other method to change the name of a file?

1 Answer

0 votes
by (25.1k points)

You can definitely write a script that will rename a file. For that you can use the OS module in python. It contains a built in method called rename which you can use to rename a file. Like this:

import os

os.rename("wrong.py","right.py")

Here, wrong.py file has been renamed to right.py file. 

Here's a python course which can help you get a deeper understanding of python and it's libraries

Related questions

0 votes
1 answer
asked Aug 1, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
asked Jul 5, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer
asked Sep 26, 2019 in Python by Sammy (47.6k points)

Browse Categories

...