Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python3 os.renames() Method

Python3 os.renames() Method

Python3 OS File/Directory Methods Python3 OS File/Directory Methods


Overview

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

Syntax

The **renames()** method syntax is as follows:


os.renames(old, new)

Parameters

Return Value

This method has no return value

Example

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


#!/usr/bin/python3

import os, sys
print ("当前目录为: %s" %os.getcwd())

# List directory
print ("目录为: %s"%os.listdir(os.getcwd()))

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

print ("重命名成功。")

# List the renamed file "aa1.txt"
print ("目录为: %s" %os.listdir(os.getcwd()))

The output of the above program is:


当前目录为: /tmp
Directory is:
 [  'a1.txt','resume.doc','a3.py','aa1.txt','Administrator','newdir','amrood.admin' ]
重命名成功。
Directory is:
 [  'a1.txt','resume.doc','a3.py','Administrator','newdir','amrood.admin' ]

Python3 OS File/Directory Methods Python3 OS File/Directory Methods