Os.path usage Analysis in Python

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.