Python OS Library Learning notes

Source: Internet
Author: User

    • OS.GETCWD (): Gets the current directory
    • Os.name: Gets the operating system that is currently in use Eg:print Os.name
    • Os.remove (): Delete the specified file Eg:os.remove (' Test.txt ')
    • Os.removedirs (): Delete the specified directory Eg:os.removedirs (' TestCase ')
    • Os.system (): Run shell command Eg:os.system (' Javac ')
    • Os.mkdir (): Create a new directory Eg:os.mkdir ("TestCase")
    • Os.chdir (): Modifies the current path to the specified path Eg:os.chdir (filepath)
    • Os.listdir (): Returns all directories and files under the specified directory eg "Os.listdir (OS.GETCWD ())

Python Os.path module

  • Os.path.abspath (PATH): Returns the absolute path
  • Os.path.basename (PATH): Return file name
  • Os.path.commonprefix (list): Returns the longest path in a list (multiple paths) that all paths share
  • Os.path.dirname (PATH): Return file path
  • Os.path.exists (PATH): path exists return true, path corruption returns false
  • Os.path.lexists: Path exists return true, path corruption returns false
  • Os.path.expanduser (path) converts the "~" and "~user" contained in path to the user directory
  • Os.path.expandvars (PATH): Replace the "$name" and "${name}" contained in path based on the value of the environment variable
  • Os.path.getatime (PATH): Returns the last time it entered this path
  • Os.path.getmtime (PATH): Returns the last modified time under this path
  • Os.path.getctime (PATH): Returns the size of path
  • Os.path.getsize (PATH): Returns the file size and returns an error if the file does not exist
  • Os.paht.isabs (PATH)
  • Os.path.isfile (PATH)
  • Os.path.isdir (PATH)
  • Os.path.islink (PATH)
  • Os.path.ismount (PATH)
  • Os.path.join (path1[,path2[,...])
  • Os.path.normcase (PATH): Convert the case and slash of path
  • Os.path.normpath (PATH): Canonical path string form
  • Os.path.realpath (PATH)
  • Os.path.relpath (Path[,start]): Calculates relative path starting from start
  • Os.path.samefile (PATH1,PATH2)
  • Os.path.samestat (STAT1,STAT2): Interpreting stat tuple STAT1 and stat2 pointing to the same file
  • Os.path.sameopenfile (FP1,FP2):
  • Os.path.split (PATH): Splits a path into dirname and basename, returning a tuple
  • Os.path.splitdriver (PATH): Typically under Windows, return the drive name and path consisting of Ganso
  • Os.path.splitunc (PATH): Splits the path into the load point and file
  • Os.path.walk (path,visit,arg): Traverse path, enter each directory to call visit function, visit must have three parameters (Arg,dirname,names), dirname represents the directory name of the current directory, Names represents all file names in the current directory, and Args is the third parameter of walk
  • Os.path.supports_unicode_filenames: Sets whether Unicode path names are supported

Python OS Library Learning notes

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.