Latest web development tutorials

Python3 os.rmdir () method

Python3 OS file / directory methods Python3 OS file / directory methods


Outline

os.rmdir () method is used to delete the specified directory path. Only when this folder is empty before they can otherwise be thrown OSError.

grammar

rmdir () method syntax is as follows:

os.rmdir(path)

parameter

  • path - path to the directory you want to delete

return value

This method does not return value

Examples

The following example demonstrates rmdir () method of use:

#!/usr/bin/python3

import os, sys

# 列出目录
print ("目录为: %s"%os.listdir(os.getcwd()))

# 删除路径
os.rmdir("mydir")

# 列出重命名后的目录
print ("目录为: %s" %os.listdir(os.getcwd()))

The above program output is:

目录为:
[  'a1.txt','resume.doc','a3.py','mydir' ]
目录为:
[  'a1.txt','resume.doc','a3.py' ]

Python3 OS file / directory methods Python3 OS file / directory methods