How to change folder name in Python

Here in this tutorial, we will learn how to change the folder name in Python.

Changing folder name in Python

Changing a folder name is quite simple in Python with the help of in-built functions.

import os

os.renames('folder1','newfolder')

Here we have imported the “os” library which in turn is a part of the standard library and provides functionality with folders such as creating or deleting folders, making changes within the folder, working with the content of the folder, etc.

Changing folder name is a very basic task to perform with the os library as it comes with the in-built function os.renamesĀ  which takes two arguments :

  1. Current folder name
  2. The new name to which we want to change

we already have a folder named ‘folder1’ with us and we want to change its name from “folder1” to “newfolder”.

And just by running the program, the folder name will change.

Thus we have seen how to change the folder name using Python.

Leave a Reply

Your email address will not be published.