Analysis of OS. path usage and pythonos. path usage in Python

Source: Internet
Author: User

Analysis of OS. path usage and pythonos. path usage in Python

This article analyzes the usage of OS. path in Python. Share it with you for your reference. The details are as follows:
Copy codeThe 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") # last access time
Print OS. path. getmtime ("d: \ new") # Last modified path time
Print OS. path. getctime ("d: \ new") # Creation Time
Print OS. path. getsize ("d: \ new \") # The size of the path is in bytes.
Print OS. path. isabs ("d :\\") # whether it is an absolute path
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") # Relative path
Print OS. path. split ("d: \ new \ hello.txt") # separate file names
Print OS. path. splitdrive ("d :\\ new \ hello.txt") # detach a disk drive
Print OS. path. splitext ("d :\\ new \ hello.txt") # separated Extension
  
Running 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 Python programming.

Related Article

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.