Back

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

I am unable to rename my file using "refractor" option. Can it be done by writing a script or is there any other method to rename a file?

 

1 Answer

0 votes
by (106k points)

There are many ways by which you can rename the file in Python some of the important is as follows:-

The first thing you can use "os.rename" for that. You can refer to the below code that shows how to use it:

import os

os.rename("a.py","test.py")

So in the above code, the a.py file has been renamed to "test.py" file. 

Another way you can use is to use the shutil module below is the code for the same:-

import shutil

shutil.move('a.txt', 'b.kml')

Related questions

0 votes
1 answer
asked Feb 10, 2020 in Python by Rajesh Malhotra (19.9k 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

...