Python3 os.rmdir() 方法

Python 3 教程 · 2019-02-07 19:12:19

概述

os.rmdir() 方法用于删除指定路径的目录。仅当这文件夹是空的才可以, 否则, 抛出OSError。

语法

rmdir()方法语法格式如下:

os.rmdir(path)

参数

  • path -- 要删除的目录路径

返回值

该方法没有返回值

实例

以下实例演示了 rmdir() 方法的使用:

#!/usr/bin/python3

import os, sys

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

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

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

执行以上程序输出结果为:

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

点击查看所有 Python 3 教程 文章: https://codercto.com/courses/l/10.html

查看所有标签

High Performance Python

High Performance Python

Andrew Lewis / O'Reilly Media, Inc. / 2010-09-15 / USD 34.99

Chapter 1. Introduction Section 1.1. The High Performance Buzz-word Chapter 2. The Theory of Computation Section 2.1. Introduction Section 2.2. Problems Section 2.3. Models of Computati......一起来看看 《High Performance Python》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

html转js在线工具
html转js在线工具

html转js在线工具