Python模块os
来源:互联网 发布:51单片机串口通信程序 编辑:程序博客网 时间:2024/05/16 04:41
1、参考链接
https://docs.python.org/3/library/os.html2、os常用用法
# 重命名文件t1.txt到t2.txt。os.rename( "t1.txt", "t2.txt" )
# 删除一个已经存在的文件test2.txt
os.remove("test2.txt")
# 创建目录test
os.mkdir("test")
# 将当前目录改为"/data/sdv1"
os.chdir("/data/sdv1")
# 获取当前的目录
os.getcwd()
# 删除”/tmp/0430”目录
os.rmdir( "/tmp/0430")
#列出dirname下的目录和文件
os.listdir(dirname):
#返回当前目录('.')
os.curdir
#dir为要删除的文件夹或者文件路径
os.remove(dir)
#path要删除的目录的路径。需要说明的是,使用os.rmdir删除的目录必须为空目录,否则函数出错。
os.rmdir(path)
#获取文件的修改时间
os.stat(path).st_mtime
#获取文件修改时间
os.stat(path).st_ctime
#获取文件的创建时间
os.path.getctime(name)
3、其他用法
os.path.isdir(name):判断name是不是一个目录,name不是目录就返回falseos.path.isfile(name):判断name是不是一个文件,不存在name也返回false
os.path.exists(name):判断是否存在文件或目录name
os.path.getsize(name):获得文件大小,如果name是目录返回0L
os.path.abspath(name)#获得绝对路径
os.path.normpath(path):规范path字符串形式
os.path.split(name):分割文件名与目录(事实上,如果你完全使用目录,它也会将最后一个目录作为文件名而分离,同时它不会判断文件或目录是否存在)
os.path.splitext():分离文件名与扩展名
os.path.join(path,name):连接目录与文件名或目录
os.path.basename(path):返回文件名
os.path.dirname(path):返回文件路径
0 0
- Python 模块学习:os模块
- Python 模块学习:os模块
- Python 模块学习:os模块
- Python 模块学习:os模块
- Python模块学习-os模块
- Python 模块学习:os模块
- Python 模块学习:os模块
- Python 模块学习:os模块
- Python 模块学习:os模块
- Python 模块学习:os模块
- Python 模块学习:os模块
- Python:os模块-subprocess模块
- Python 模块学习:os模块
- python模块之os模块
- Python 模块学习:os模块
- Python 模块学习:os模块
- Python 模块学习:os模块
- Python 模块学习:os模块
- 关于PHP内部编码与mysql字符差异问题的研究
- RecyclerView实现时光轴效果
- 【转载】C++常见问题: 字符串分割函数 split
- 梯度下降法
- ArduPilot源码学习--(一)--MAC下编译ArduPilot源码
- Python模块os
- Hibernate学习笔记之一
- EJB 是什么
- 使用Axis2技术发布webservice接口,使用wsCaller.jar工具测试接口
- LeetCode 121. Best Time to Buy and Sell Stock
- linux查看端口
- C语言基础:字符输入/输出验证
- weston快捷键
- 测试工具比较