www.colben.cn/content/post/python-os.md
2021-11-14 14:32:08 +08:00

27 lines
1.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: "Python 的 os 和 os.path"
date: 2019-10-30T17:45:33+08:00
lastmod: 2019-10-30T17:45:33+08:00
tags: ["python", "os", "os.path"]
categories: ["python"]
---
- os.getcwd() #返回运行脚本的目录
- os.listdir() #获取目录中的内容
- os.path.basename() #去掉目录路径,返回文件名
- os.path.dirname() #去掉文件名,返回目录路径
- os.path.join() #组合成合法路径
- os.path.split() #返回路径和文件名元组
- os.path.splitdrive() #返回驱动器符号和路径元组
- os.path.splitext() #返回文件名和扩展名元组
- os.path.getatime() #返回文件最近的访问时间戳
- os.path.getctime() #返回文件的创建时间戳
- os.path.getmtime() #返回文件修改时间
- os.path.getsize() #返回文件大小Bytes
- os.path.exists() #指定目录或文件是否存在
- os.path.isabs() #指定路径是否为绝对路径
- os.path.isdir() #指定路径是否为目录
- os.path.isfile() #指定路径是否为文件
- os.path.samefile() #指定路径名是否指向同一个文件