Python3 Os Removedirs
# Python3.x Python3 os.removedirs() Method
[ Python3 OS File/Directory Methods](#)
* * *
### Overview
The os.removedirs() method is used to recursively delete directories. Like rmdir(), if a subfolder is successfully deleted, removedirs() will attempt to delete its parent folder, until an error is raised (which is generally ignored, as it typically means the folder is not empty).
### Syntax
The syntax for the **removedirs()** method is as follows:
os.removedirs(path)
### Parameters
* **path** -- The path of the directory to be removed.
### Return Value
This method does not return a value.
### Example
The following example demonstrates the use of the removedirs() method:
#!/usr/bin/python3import os, sys # List directoriesprint ("The directory is: %s" %os.listdir(os.getcwd()))# Remove os.removedirs("/test")# List directories after removalprint ("The directory after removal is:" %os.listdir(os.getcwd()))
The output of executing the above program is:
The directory is:[ 'a1.txt','resume.doc','a3.py','test' ]The directory after removal is:[ 'a1.txt','resume.doc','a3.py' ]
[ Python3 OS File/Directory Methods](#)
YouTip