python os.path 的用法
2016-10-16 00:22
776 查看
#coding=utf-8
import os
print os.path.abspath("d:\\new\\test.txt")
print os.path.basename("d:\\new\\test.txt")
print os.path.exists("d:\\new")
print os.path.lexists("d:\\new")
print os.path.expanduser("d:\\new\\text.txt")
print os.path.getatime("d:\\new") #最后访问时间
print os.path.getmtime("d:\\new") #最后修改路径时间
print os.path.getctime("d:\\new") #创建时间
print os.path.getsize("d:\\new\\") #或许路径的大小 字节为单位
print os.path.isabs("d:\\") #是否是绝对路径
print os.path.isfile("d:\\new\\hello.txt")
print os.path.isdir("d:\\new")
print os.path.islink("d:\\new\\hello.txt")
print os.path.join("d:\\new","hello.txt")
print os.path.normcase("d:\\new\\hello.txt")
print os.path.relpath("d:\\new\\hello.txt") #相对路径
print os.path.split("d:\\new\\hello.txt") #分离文件名
print os.path.splitdrive("d:\\new\\hello.txt") #分离磁盘驱动器
print os.path.splitext("d:\\new\\hello.txt") #分离扩展名
>>>
d:\new\test.txt
test.txt
d:\new
True
True
d:\new\text.txt
1322235096.47
1322235096.47
1321610018.9
16384
True
True
True
False
d:\new\hello.txt
d:\new\hello.txt
hello.txt
('d:\\new', 'hello.txt')
('d:', '\\new\\hello.txt')
('d:\\new\\hello', '.txt')
>>>
import os
print os.path.abspath("d:\\new\\test.txt")
print os.path.basename("d:\\new\\test.txt")
print os.path.exists("d:\\new")
print os.path.lexists("d:\\new")
print os.path.expanduser("d:\\new\\text.txt")
print os.path.getatime("d:\\new") #最后访问时间
print os.path.getmtime("d:\\new") #最后修改路径时间
print os.path.getctime("d:\\new") #创建时间
print os.path.getsize("d:\\new\\") #或许路径的大小 字节为单位
print os.path.isabs("d:\\") #是否是绝对路径
print os.path.isfile("d:\\new\\hello.txt")
print os.path.isdir("d:\\new")
print os.path.islink("d:\\new\\hello.txt")
print os.path.join("d:\\new","hello.txt")
print os.path.normcase("d:\\new\\hello.txt")
print os.path.relpath("d:\\new\\hello.txt") #相对路径
print os.path.split("d:\\new\\hello.txt") #分离文件名
print os.path.splitdrive("d:\\new\\hello.txt") #分离磁盘驱动器
print os.path.splitext("d:\\new\\hello.txt") #分离扩展名
>>>
d:\new\test.txt
test.txt
d:\new
True
True
d:\new\text.txt
1322235096.47
1322235096.47
1321610018.9
16384
True
True
True
False
d:\new\hello.txt
d:\new\hello.txt
hello.txt
('d:\\new', 'hello.txt')
('d:', '\\new\\hello.txt')
('d:\\new\\hello', '.txt')
>>>
相关文章推荐
- 详解Python中的join()函数的用法(字符串和os.path)
- python基础(一)--join和os.path.join函数的用法以及字符串格式化
- Python学习:纠错笔记:详解os.removedirs(path)的正确用法
- python中的os.path模块用法(一)
- python3中,os.path模块下常用的用法总结
- 详解Python中的join()函数的用法(字符串和os.path)
- Python中os.path用法分析
- python笔记005——os.path模块用法详解
- python中关于os.path.file的详细用法
- Python中.join()和os.path.join()两个函数的用法详解
- Python中join函数和os.path.join用法以及一句话输出九九乘法表
- Python中的join()函数的用法(字符串和os.path)
- Python的os.path常见用法
- Python中os.path用法分析
- Python_API_os.path_walk_待填充
- python os.path模块
- Python os.path模块
- Python_API_os.path_splitdrive_待填充
- Python_API_File and Directory Access_os.path.splitext
- Python_API_File and Directory Access_os.path.join