Python OS operations, pythonos
1. OS. path. driname (path): return the upper-level path string of the path.
>>> OS. path. dirname ('d: \ Games ')
'D :\\'
>>>
2. OS. path. basename (path): return the last-level directory name (Folder name) or file name (full name) of the path ).
>>> 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 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): determines whether a path is a file.
7. OS. listdir (dir_path): returns the names of all files (full names) and folders in 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): delete a specified file.
9. OS. removedirs (dir_path): Delete the specified empty directory (empty folder ).
10. OS. path. exists (path): determines whether a path exists.
11. OS. mkdir (path): create a directory (folder ).
12. OS. getcwd (): Get the current working directory.