This paper analyzes the usage of Os.path in Python. Share to everyone for your reference. Specific as follows:
The code is 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\\") #或许路径的大小 bytes
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 ") #分离扩展名
Operation 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 ')
>>>
Hopefully this article will help you with Python programming.