Python method removedirs() removes dirs recursively. If the leaf directory is successfully removed, removedirs tries to successively remove every parent directory displayed in the path.
Following is the syntax for removedirs() method:
os.removedirs(path)
This method does not return any value.
The following example shows the usage of removedirs() method.
# !/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())
When we run the above program, it produces the 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' ]
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.