Python built-in module--os module use

Source: Internet
Author: User

The OS module is the interaction module between the interpreter and the operating system, using the OS module

#OS module use, as soon as possible to resolve, file additions and deletions to searchImportOSOS.GETCWD ()#gets the current working directory, the path of the current script workOs.chdir ("Path")#change the current script working directory, quite go to CD switch directoryOs.curdir ()#return to current directoryOs.pardir ()#Gets the parent directory string for the current directoryOs.makedirs ("path1/path2")#Multi-level recursive catalogs can be generatedOs.removedirs ("path1")#If the directory is empty then delete, and recursively to the previous layer, if also empty, continue to deleteOs.mkdir ("File_path")#generate a single-level empty directoryOs.listdir ("dirname")#lists all files and subdirectories under the specified directory, including hidden files, displayed as a listOs.remove ("Oldfile","NewFile")#renaming a file/directoryOs.stat ("Path/filename")#get file, directory informationOs.sep ()#output operating system specific path delimiter, solve win under and Liunx '/' and '// 'Os.linesep ()#output for splitting file pathsOs.system ("dir")#Run the shell commandOs.environ ()#Get Environment VariablesOs.path.split (OS.GETCWD ())#Split Environment VariablesOs.path.dirname (__file__) os.path.exists (path)#Returns true if path exists, false if path does not existOs.path.isabs (PATH)#returns True if path is an absolute pathOs.path.isfile (PATH)#returns True if path is a file that exists. Otherwise returns falseOs.path.isdir (PATH)#returns True if path is a directory that exists. Otherwise returns falseOs.path.join (path1[, path2[, ...])#when multiple paths are combined, the parameters before the first absolute path are ignoredOs.path.getatime (PATH)#returns the last access time of the file or directory to which path is pointingOs.path.getmtime (PATH)#returns the last modified time of the file or directory to which path is pointingOs.path.getsize (PATH)#returns the size of path

Python built-in module--os module use

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.