Python os.rmdir() method
Python OS file/directory methods
Overview
The os.rmdir() method deletes the directory at the specified path. It only works when the folder is empty; otherwise OSError is raised.
Syntax
The **rmdir()** method syntax is as follows:
os.rmdir(path)
Parameters
-
path -- The path of the directory to delete
Return Value
This method has no return value
Example
The following example demonstrates the use of the rmdir() method:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os, sys
# List directory
print "目录为: %s"%os.listdir(os.getcwd())
# Delete path
os.rmdir("mydir")
# List renamed directories
print "目录为: %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' ]