Rename a folder

EasyOS Module Programs · 39 of 49

Write a Python program to rename a folder with os.rename().

Advertisement
Output
False True

Approach

  1. os.rename(old, new).

Solution

Python
import os os.makedirs("old_name", exist_ok=True)if os.path.exists("new_name"):    os.rmdir("new_name")os.rename("old_name", "new_name")print(os.path.isdir("old_name"), os.path.isdir("new_name"))
Output
False True

Learn the concept

New to this topic? Read the lesson, then come back.

More os module programs

← All 49 OS Module Programs

Leave a Comment