YouTip LogoYouTip

Python3 Os Rmdir

# Python3.x Python3 os.rmdir() Method [![Image 3: Python3 OS File/Directory Methods](#) Python3 OS File/Directory Methods](#) * * * ### Overview The `os.rmdir()` method is used to delete a specified directory. 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 the directoryprint ("The directory is: %s"%os.listdir(os.getcwd()))# Delete the path os.rmdir("mydir")# List the directory after deletionprint ("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' ] [![Image 4: Python3 OS File/Directory Methods](#) Python3 OS File/Directory Methods](#)
← Python3 Os RmdirPython3 Os Rename β†’