小白教程
所有教程
关于
Search
172.69.58.173
172.69.58.173
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python3 os removedirs”的源代码
本页内容
上一节:
Python3_os_remove
下一节:
Python3_os_rename
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:os.removedirs(path)}}[[Category:python3 os file methods|46]] = Python3 os.removedirs() 方法 = [[python3 os file methods|Python3 OS 文件/目录方法]] === 概述 === os.removedirs() 方法用于递归删除目录。像rmdir(), 如果子文件夹成功删除, removedirs()才尝试它们的父文件夹,直到抛出一个error(它基本上被忽略,因为它一般意味着你文件夹不为空)。 === 语法 === '''removedirs()'''方法语法格式如下: <sample title="" desc="" lang="python" hererun="1"> os.removedirs(path) </sample> === 参数 === * '''path''' -- 要移除的目录路径 === 返回值 === 该方法没有返回值 == 以下实例演示了 removedirs() 方法的使用: <sample title="" desc="" lang="python" hererun="1"> #!/usr/bin/python3 import os, sys # 列出目录 print ("目录为: %s" %os.listdir(os.getcwd())) # 移除 os.removedirs("/test") # 列出移除后的目录 print ("移除后目录为:" %os.listdir(os.getcwd())) </sample> 执行以上程序输出结果为: <sample title="" desc="" lang="python" hererun="1"> 目录为: [ 'a1.txt','resume.doc','a3.py','test' ] 移除后目录为: [ 'a1.txt','resume.doc','a3.py' ] </sample> [[python3 os file methods|Python3 OS 文件/目录方法]]
返回至“
Python3 os removedirs
”。
上一节:
Python3_os_remove
下一节:
Python3_os_rename