YouTip LogoYouTip

Os Rmdir

# Python2.x Python os.rmdir() Method [![Image 3: Python File Methods](#) Python OS File/Directory Methods](#) * * * ### Overview The `os.rmdir()` method is used to delete a specified directory path. This can only be done if the folder is empty; otherwise, an `OSError` is raised. ### 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/python# -*- coding: UTF-8 -*-import os, sys # List directoryprint "Directory is: %s"%os.listdir(os.getcwd())# Remove path os.rmdir("mydir")# List renamed directoryprint "Directory is: %s" %os.listdir(os.getcwd()) The output of the above program is: Directory is:[ 'a1.txt','resume.doc','a3.py','mydir' ]Directory is:[ 'a1.txt','resume.doc','a3.py' ] [![Image 4: Python File Methods](#) Python OS File/Directory Methods](#)
← Django ViewsDjango Intro β†’