OS.SEP can replace the operating system-specific path delimiter. The ' \ \ ' Os.name string under Windows indicates the platform you are using. For example, for Windows, it is ' NT ', and for Linux/unix users, it is the ' POSIX ' os.getcwd () function to get the current working directory, that is, the directory path of the current Python script work os.getenv () Gets an environment variable, If you do not return noneos.putenv (key, value), set an environment variable value os.listdir (path) to return all file and directory names under the specified directory Os.remove (path) function to delete a file Os.system (com Mand) function to run the shell command Os.linesep string gives the line terminator used by the current platform. For example, Windows uses ' \ r \ n ', Linux uses ' \ n ' and Mac uses the ' \ R ' os.path.split (path) function to return a path of directory name and filename os.path.isfile () and Os.path.isdir ( ) function to verify whether the given path is a file or a directory os.path.exists () function to verify that the given path really exists Os.curdir returns the current directory ('. ') Os.mkdir (path) creates a directory Os.makedirs (path) recursive creation directory Os.chdir (dirname) changes working directory to dirname Os.path.getsize (name) Get the file size, if name is directory return 0los.path.abspath (name) get absolute path Os.path.normpath (PATH) specification path string Form Os.path.splitext () detach file name with extension The name Os.path.join (path,name) connection directory with the file name or directory Os.path.basename (path) returns the file name Os.path.dirname (path) back to the path Os.walk (top,topdown=t Rue,onerror=none) Traverse 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 the 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 current DST already exists then it will be overwritten shutil.move (SRC, DST) move file or rename Shutil.copymode (SRC, DST) just copy its permissions other things will not be 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) on copy on the basis of the re- The last access time and modification time of the file are also copied, similar to the cp–p stuff shutil.copy2 (src, DST) if the two location file system is the same as the rename operation, just renamed; if it's not on the same filesystem, it's a move operation S. Hutil.copytree (Olddir, Newdir, true/flase) copies the olddir copy newdir, if the 3rd parameter is True, the symbolic connection under the folder is 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 contents within the directory
Python default module OS and Shutil utility functions