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.