Python--os Module

Source: Internet
Author: User

Provides an interface to invoke the operating system

1 os.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 returns the current directory: ('.')4Os.pardir Gets the parent directory string name for the current directory: ('..')5Os.makedirs ('dirname1/dirname2') to generate a multi-level recursive directory6Os.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') to generate a single-level directory, equivalent to the shell mkdir dirname8Os.rmdir ('dirname'Delete the 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 listTen os.remove () Delete a file oneOs.rename ("oldname","newname") Rename file/Catalogue aOs.stat ('Path/filename') Get file/directory information -OS.SEP output Operating system-specific path delimiter, win under"\\", under Linux for"/" -OS.LINESEP output The line terminator used by the current platform, win under"\t\n", under Linux for"\ n" the os.pathsep output string for splitting the file path -The Os.name output string indicates the current usage platform. Win->'NT'; Linux->'POSIX' -Os.system ("Bash Command") to run the shell command to display directly - Os.environ getting system environment variables + Os.path.abspath (path) Returns the absolute path normalized by path - os.path.split (path) splits 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) a os.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) at os.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--os Module

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.