Python3 Os Rmdir
# Python3.x Python3 os.rmdir() Method
[ Python3 OS File/Directory Methods](#)
* * *
### Overview
The `os.rmdir()` method is used to delete a specified directory path. It can only be used if the folder is empty; otherwise, it raises an `OSError`.
### Syntax
The syntax for the `rmdir()` method is as follows:
os.rmdir(path)
### Parameters
* **path** -- The path of the directory to be deleted.
### Return Value
This method does not return a value.
### Example
The following example demonstrates the use of the `rmdir()` method:
#!/usr/bin/python3import os, sys # List directoryprint ("The directory is: %s"%os.listdir(os.getcwd()))# Delete path os.rmdir("mydir")# List renamed directoryprint ("The directory is: %s" %os.listdir(os.getcwd()))
The output of executing the above program is:
The directory is:[ 'a1.txt','resume.doc','a3.py','mydir' ]The directory is:[ 'a1.txt','resume.doc','a3.py' ]
[ Python3 OS File/Directory Methods](#)
YouTip