YouTip LogoYouTip

Os Renames

# Python2.x Python os.renames() Method [![Image 3: Python File Methods](#) Python OS File/Directory Methods](#) * * * ### Overview The os.renames() method is used to recursively rename a directory or file. It is similar to rename(). ### Syntax The syntax for the **renames()** method is as follows: os.renames(old, new) ### Parameters * **old** -- The directory to be renamed * **new** -- The new name for the file or directory. It can even be a file contained within a directory, or a complete directory tree. ### Return Value This method does not return a value. ### Example The following example demonstrates the use of the renames() method: ## Example #!/usr/bin/python # -*- coding: UTF-8 -*- import os,sys print"Current directory is: %s" %os.getcwd() # List directory print"Directory is: %s"%os.listdir(os.getcwd()) # Rename "aa1".txt" os.renames("aa1.txt","newdir/aanew.txt") print"Rename successful. # List renamed file "aa1".txt" print"Directory is: %s" %os.listdir(os.getcwd()) The output of executing the above program is: Current directory is: /tmp Directory is: [ 'a1.txt','resume.doc','a3.py','aa1.txt','Administrator','amrood.admin' ]Rename successful.Directory is: [ 'a1.txt','resume.doc','a3.py','Administrator','amrood.admin' ] [![Image 4: Python File Methods](#) Python OS File/Directory Methods](#)
← Os Stat_Float_TimesOs Renames β†’