You are here : python_2ososremovedirs

os.removedirs() - os

             

The method removedirs() removes dirs recursively. If the leaf directory is succesfully removed, removedirs tries to successively remove every parent directory displayed in path.


  • path -- This is the path of the directory, which needs to be removed.


Syntax


os.removedirs(path)


Example


# !/usr/bin/python

import os, sys

# listing directories
print "The dir is: %s" %os.listdir(os.getcwd())

# removing
os.removedirs("/tutorialsdir")

# listing directories after removing directory
print "The dir after removal is:" %os.listdir(os.getcwd())


Output / Return Value

When we run above program, it produces following result:


The dir is: [ 'a1.txt','resume.doc','a3.py','tutorialsdir','amrood.admin' ] The dir after removal is: [ 'a1.txt','resume.doc','a3.py','amrood.admin' ]


Limitations


Alternatives / See Also


Reference