# OS Module
OS.SEP can replace the operating system-specific path delimiter. windows for ' \ \ '
The Os.name string indicates the platform you are using. For example, for Windows, it's ' NT ', and for Linux/unix users, it's ' POSIX '
The OS.GETCWD () function gets the current working directory, which is the directory path of the current Python script work
Os.getenv () Gets an environment variable if none is returned
Os.putenv (key, value) sets an environment variable value
Os.listdir (path) returns all file and directory names under the specified directory
The Os.remove (path) function is used to delete a file
Os.system (command) function to run the shell command
The OS.LINESEP string gives the line terminator used by the current platform. For example, Windows uses ' \ r \ n ', Linux uses ' \ n ' and Mac uses ' \ R '
The Os.path.split (path) function returns the directory name and file name of a path
The Os.path.isfile () and Os.path.isdir () functions respectively verify that the given path is a file or a directory
The os.path.exists () function is used to verify that the given path really exists
Os.curdir returns the current directory ('. ')
Os.mkdir (path) Create a directory
Os.makedirs (path) to create a directory recursively
Os.chdir (dirname) Change working directory to DirName
Os.path.getsize (name) Gets the file size if name is directory returned 0L
Os.path.abspath (name) gets the absolute path
Os.path.normpath (path) canonical path string form
Os.path.splitext () detach file name and extension
Os.path.join (path,name) connection directory with file name or directory
Os.path.basename (path) returns the file name
Os.path.dirname (path) return file path
Os.walk (top,topdown=true,onerror=none) Traversal Iteration Directory
Os.rename (SRC, DST) rename file or directory src to DST if DST is an existing directory, the OSError will be thrown. In Unix, if DST is stored and is a file, it will be silently replaced if the user has permission. The operation will fail in some UNIX if SRC and DST are in different file systems. If successful, this naming operation will be an atomic operation (this is POSIX required). On Windows, if DST already exists, OSError will be thrown, even if it is a file. Valid in Unix,windows.
Os.renames (old, new) recursively renames a folder or file. Like rename ()
# Shutil Module
Shutil.copyfile (SRC, DST) is copied from source Src to DST. The premise is, of course, that the destination address has writable permissions. The exception information thrown is IOException. If the current DST already exists, it will be overwritten.
Shutil.move (SRC, DST) move files or rename
Shutil.copymode (SRC, DST) just replicates its permissions other things are not copied
Shutil.copystat (SRC, DST) copy permissions, last access time, last modified time
Shutil.copy (SRC, DST) copy a file to a file or a directory
Shutil.copy2 (SRC, DST) copy files on the basis of copy the last access time and modification time are also copied, similar to cp–p things
Shutil.copy2 (SRC, DST) if the file system in two locations is the same, it is equivalent to rename operation, just renaming; if it's not the same filesystem, it's a move operation.
Shutil.copytree (Olddir, Newdir, True/flase)
Copy the Olddir to a newdir, if the 3rd parameter is true, the symbol connection under the folder will be kept when the directory is copied, and if the 3rd parameter is false, a physical copy will be generated in the replicated directory instead of the symbolic connection
Shutil.rmtree (SRC) recursively deletes a directory and all content within the directory
A collection of practical methods for OS and shutil modules in Python