The OS module provides a number of features that allow your program to interact directly with the operating system
Gets the current working directory, which is the directory path of the current Python interpreter work: OS. getcwd() returns all file and directory names under the specified directory: OS. listdir() function to delete a file: OS. remove() Delete multiple directories: OS. Removedirs (r "C:\python") verifies whether the given path is a file: OS. path. isfile(Verify that the given path is a directory: OS. path. isdir() to determine if it is an absolute path: OS. path. isabs() to verify that the given path is actually stored in the: OS. path. exists() returns the directory name and file name of a path: OS. path. split() E. G OS. path. split('/home/swaroop/byte/code/poem.txt 'Results('/home/swaroop/byte/code ',' Poem.txt ') Detach extension: OS. path. splitext() E. G OS. path. splitext('/usr/local/test.py 'Results('/usr/local/test ','. Py 'Get path name: OS. path. dirname() to obtain an absolute path: OS. path. abspath() Get file name: OS. path. basename() to run the shell command: OS. system(Read the operating system environment variable home value: OS. getenv("HOME") returns all environment variables for the operating system: OS. Environ set the system environment variable, only valid when the program is running: OS. Environ. SetDefault(' HOME ','/home/alex ') gives the line terminator used by the current platform: OS. Linesep Windows uses' \ r \ n ', Linuxand Mac use' \ n ' indicates the platform you are using: OS. name for Windows, which is' NT ', and for Linux/unix User, it is' POSIX ' rename: os. Rename (old, new) create a multilevel directory: OS. Makedirs (r "C:\python\test") Create a single directory: OS. mkdir ("test") Get file properties: OS. stat ("file") modifying file permissions and timestamps: OS. chmod (file) Get file size: OS. path.getsize (filename) combined with directory name and file name: Os.path.join (Dir,filename: Os (Dirname.get_terminal_size (: Os.kill (10884,signal)
Python base-os module