Operating Methods of Python OS (detailed description), pythonos

Source: Internet
Author: User

Operating Methods of Python OS (detailed description), pythonos

1. OS. path. driname (path ):Returns the upper-level path string of the path.

  >>> os.path.dirname('D:\Games')  'D:\\'  >>>

2. OS. path. basename (path ):Return the name of the last level directory (Folder name) or file in the path (full name ).

>>> OS. path. basename ('d: \ Games \ 9yin_632 \ snail bag \ 0x0804. ini ') '0x0804. ini' >>>

3. OS. path. splitext (file_name ):Returns a tuple consisting of a file name and its suffix.

  >>> os.path.splitext('0x0804.ini')  ('0x0804', '.ini')  >>>

4. OS. path. abspath (string ):Returns the path string consisting of the path of the current working directory and a string.

>>> OS. path. abspath ('games') # There is no "Games" file or folder in the current directory, just a random string 'C: \ Python27 \ games'>

5. OS. path. isdir (path ):Determines whether a path is a directory (folder ).

6. OS. path. isfile (path ):Determine whether a path is a file.

7. OS. listdir (dir_path ):Return the names of all files (full names) and folders under a directory (dir_path can only be a directory, not a file name path) in the form of a list.

8. OS. remove (file_path ):Deletes a specified file.

9. OS. removedirs (dir_path ):Delete the specified empty directory (empty folder ).

10. OS. path. exists (path ):Determine whether a path exists.

11. OS. mkdir (path ):Create a directory (folder ).

12. OS. getcwd ():Obtain the current working directory.

The operating method of the above Python OS (detailed description) is all the content that I have shared with you. I hope to give you a reference and support for the help house.

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.