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.
os.rmdir(path)
# !/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())
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'