When working with servers you mostly get a terminal to perform different functions. Sometimes you need to write a different script that requires you to rename a file or directory. Let’s take a look at how to rename a file and directory using Python “os” library.
There is a python built-in function os.rename(src, dest) that take two arguments source location of the file or directory and destination location of the file or directory.
Renaming File
Let’s run the following code.
import os |
Renaming Directory
Now let’s rename the directory. Renaming directory is same as renaming file.
Let’s execute the following code to rename the directory.
import os |