Easy Tutorial
❮ Python Factorial Ref Set Symmetric_Difference_Update ❯

Python3 os.renames() Method

Python3 OS File/Directory Methods


Overview

The os.renames() method is used for recursively renaming directories or files. It is similar to rename().

Syntax

The syntax for the renames() method is as follows:

os.renames(old, new)

Parameters

Return Value

This method does not return any value.

Example

The following example demonstrates the use of the renames() method:

#!/usr/bin/python3

import os, sys
print ("Current directory is: %s" %os.getcwd())

# List the directory
print ("Directory is: %s"%os.listdir(os.getcwd()))

# Rename "aa1.txt"
os.renames("aa1.txt","newdir/aanew.txt")

print ("Rename successful.")

# List the renamed file "aa1.txt"
print ("Directory is: %s" %os.listdir(os.getcwd()))

Executing the above program will output:

Current directory is: /tmp
Directory is:
 [  'a1.txt','resume.doc','a3.py','aa1.txt','Administrator','newdir','amrood.admin' ]
Rename successful.
Directory is:
 [  'a1.txt','resume.doc','a3.py','Administrator','newdir','amrood.admin' ]

Python3 OS File/Directory Methods

❮ Python Factorial Ref Set Symmetric_Difference_Update ❯