An example of this article is an analysis of os.path usage in Python. Share to everyone for your reference. Specifically as follows:
Copy Code code as follows:
#coding =utf-8
Import OS
Print Os.path.abspath ("D:\\new\\test.txt")
Print Os.path.basename ("D:\\new\\test.txt")
Print Os.path.dirname ("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\\") #或许路径的大小 byte units
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") #分离扩展名
Run Result:
>>>
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 ')
>>>
I hope this article will help you with your Python programming.