The OS module operates as follows:
1OS.GETCWD ()#gets the current working directory, which is the directory path of the current Python script work2Os.chdir ("dirname")#change the current script working directory, equivalent to the shell CD3Os.curdir#return to current directory: ('. ')4Os.pardir#Gets the parent directory string name of the current directory: (' ... ')5Os.makedirs ('dirname1/dirname2')#Multi-level recursive catalogs can be generated6Os.removedirs ('dirname1')#If the directory is empty, it is deleted and recursively to the previous level of the directory, if it is also empty, then delete, and so on7Os.mkdir ('dirname')#generate a single-level directory, equivalent to the shell mkdir dirname8Os.rmdir ('dirname')#Delete single-level empty directory, if the directory is not empty can not be deleted, error; equivalent to the shell rmdir dirname9Os.listdir ('dirname')#lists all files and subdirectories under the specified directory, including hidden files, and prints as a listTenOs.remove ()#Delete a file OneOs.rename ("oldname","newname")#Renaming files/directories AOs.stat ('Path/filename')#Get File/directory information -Os.sep#output operating system-specific path delimiter, win under "\ \", Linux for "/" -Os.linesep#output The line terminator used by the current platform, win under "\t\n", Linux "\ n" theOs.pathsep#output A string used to split a file path -Os.name#The output string indicates the current usage platform. Win-> ' NT '; Linux-> ' POSIX ' -Os.system ("Bash Command")#run the shell command to display directly -Os.environ#Get system Environment variables +Os.path.abspath (PATH)#returns the absolute path normalized by path -Os.path.split (PATH)#split path into directory and file name two tuples returned +Os.path.dirname (PATH)#returns the directory of path. is actually the first element of Os.path.split (path) AOs.path.basename (PATH)#returns the last file name of path. If path ends with a/or \, then a null value is returned. The second element of Os.path.split (path) atOs.path.exists (PATH)#Returns true if path exists, false if path does not exist -Os.path.isabs (PATH)#returns True if path is an absolute path -Os.path.isfile (PATH)#returns True if path is a file that exists. Otherwise returns false -Os.path.isdir (PATH)#returns True if path is a directory that exists. Otherwise returns false -Os.path.join (path1[, path2[, ...])#when multiple paths are combined, the parameters before the first absolute path are ignored -Os.path.getatime (PATH)#returns the last access time of the file or directory to which path is pointing inOs.path.getmtime (PATH)#returns the last modified time of the file or directory to which path is pointing
"Python module learning" OS module