Python OS module Common methods:
OS.GETCWD () Gets the current directory, similar to the PWD in the shell. Os.chdir (' dirname ') switches the directory to the same as the CD in the shell. Os.makedirs (' dirname1/dirname2 ') cascading creates directories and mkdir-p in the shell like Os.removedirs (' dirname1 ') if the directory is empty, then deleted, and recursively to the previous level directory, if also empty , then delete, and so on. Os.mkdir (' dirname ') creates the directory, and mkdir like Os.rmdir (' dirname ') in the shell removes the empty directory, and the rmdir command in the shell is similar to Os.listdir (' dirname ') Lists all files and subdirectories under the specified directory, including hidden files, printed as a list. Similar to the ls-al in the shell. Os.remove (' filename ') delete a file Os.rename (' oldname ', ' newname ') rename the file or directory Os.stat (' Path/filename ') to get file or directory information Os.name Outputs the platform currently in use. Win ==> ' NT ', Linux runs shell command for ' POSIX ' os.system (' Bash command '), direct display Os.environ get system environment variable Os.path.abspath (' path ') Returns path with an absolute path of os.path.split (path) that splits the path into directories and filenames to return Os.path.dirname (path) to the path directory Os.path.basename (path) Ganso Returns the last file name of path. Os.path.exists (path) returns true if path exists. If path does not exist, return Flase.os.access (' path ', OS. F_OK) Whether there is os.access (' path ', OS. R_OK) is readable os.access (' path ', OS. W_OK) is writable os.access (' path ', OS. X_OK) whether os.path.isabs (path) can be executed if path is an absolute path, return True.os.path.isfile (PATH) If path is an existing file, return True.os.path.isdir (PATH) If path is a directory that exists, how to return True.os.path.join (path1,path2) to combine path1 and path2 into a path os.path.getatime (path) Returns the file that the path points to or the last access time of the directory Os.path.getmtime (path) returns the last modified time of the file or directory to which path is pointing
Reference: https://www.cnblogs.com/gide/p/5570886.html
Python OS module