Python default module OS and Shutil utility functions

Source: Internet
Author: User
Tags posix

OS.SEP can replace the operating system-specific path delimiter. Under Windows for'\\'the Os.name string indicates the platform you are using. For Windows, for example, it is'NT', and for Linux/unix users, it is'POSIX'The os.getcwd () function obtains the current working directory, that is, the directory path of the current Python script work os.getenv () Gets an environment variable if no return noneos.putenv (key, value) sets an environment variable value Os.lis Tdir (path) returns all file and directory names under the specified directory Os.remove (path) function used to delete a file Os.system (command) function used to run the shell command Os.linesep string Given the end of the line used by the current platform The stop character. For example, Windows uses'\ r \ n', Linux uses'\ n'and Mac uses'\ r'the Os.path.split (path) function returns a path to the directory name and file name Os.path.isfile () and the Os.path.isdir () function to verify whether the given path is a file or a directory os.path.exists () function is used to verify that the given path really exists Os.curdir returns the current directory ('.'Os.mkdir (path) creates a directory Os.makedirs (path) recursively creating the directory Os.chdir (dirname) changes the 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 The file name and extension Os.path.join (path,name) connection directory with the file name or directory Os.path.basename (path) returns the filename os.path.dirname (path) to return the path Os.walk (top,topd Own=true,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 rename ()#Shutil Moduleshutil.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 of 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

Python default module OS and Shutil utility functions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.