Python OS module

Source: Internet
Author: User

Python OS module Common methods:

OS.GETCWD () Gets the current directory, similar to the PWD in the shell. Os.chdir (' dirname ') switches the directory to the same as the CD in the shell. Os.makedirs (' dirname1/dirname2 ') cascading creates directories and mkdir-p in the shell like Os.removedirs (' dirname1 ') if the directory is empty, then deleted, and recursively to the previous level directory, if also empty , then delete, and so on. Os.mkdir (' dirname ') creates the directory, and mkdir like Os.rmdir (' dirname ') in the shell removes the empty directory, and the rmdir command in the shell is similar to Os.listdir (' dirname ') Lists all files and subdirectories under the specified directory, including hidden files, printed as a list. Similar to the ls-al in the shell. Os.remove (' filename ') delete a file Os.rename (' oldname ', ' newname ') rename the file or directory Os.stat (' Path/filename ') to get file or directory information Os.name Outputs the platform currently in use. Win ==> ' NT ', Linux runs shell command for ' POSIX ' os.system (' Bash command '), direct display Os.environ get system environment variable Os.path.abspath (' path ') Returns path with an absolute path of os.path.split (path) that splits the path into directories and filenames to return Os.path.dirname (path) to the path directory Os.path.basename (path) Ganso Returns the last file name of path. Os.path.exists (path) returns true if path exists. If path does not exist, return Flase.os.access (' path ', OS. F_OK) Whether there is os.access (' path ', OS. R_OK) is readable os.access (' path ', OS. W_OK) is writable os.access (' path ', OS. X_OK) whether os.path.isabs (path) can be executed if path is an absolute path, return True.os.path.isfile (PATH) If path is an existing file, return True.os.path.isdir (PATH) If path is a directory that exists, how to return True.os.path.join (path1,path2) to combine path1 and path2 into a path os.path.getatime (path) Returns the file that the path points to or the last access time of the directory Os.path.getmtime (path) returns the last modified time of the file or directory to which path is pointing

  

Reference: https://www.cnblogs.com/gide/p/5570886.html

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.