You are here : python_2ososrmdir

os.rmdir() - os

             

The method rmdir() removes the directory path. It works only when the directory is empty, else OSError is raised.


  • path -- This is the path of the directory, which needs to be removed.


Syntax


os.rmdir(path)


Example


# !/usr/bin/python

import os, sys

# listing directories
print "the dir is: %s" %os.listdir(os.getcwd())

# removing path
os.rmdir("mydir")

# listing directories after removing directory path
print "the dir is:" %os.listdir(os.getcwd())


Output / Return Value

The error is coming as 'mydir' directory is not empty. If 'mydir' is an empty directory, then this would produce following result:


the dir is: [ 'a1.txt','resume.doc','a3.py','mydir','Administrator','amrood.admin' ] os.rmdir("mydir") OSError: [Errno 90] Directory not empty: 'mydir'


Limitations


Alternatives / See Also


Reference