Python file path operation

Source: Internet
Author: User
Import Os.pathpath = '/home/vamei/doc/file.txt ' Print (os.path.basename (path))    # The file name that is contained in the query path print ( Os.path.dirname (Path)     # The directory contained in the query path info = os.path.split       # divides the path into a file name and a directory of two parts, placed in a table to return print (info) path2 = Os.path.join ('/', ' home ', ' Vamei ', ' Doc ', ' file1.txt ')  # Use directory name and file name to form a path string, string concatenation output:/home\vamei\doc\file1.txtp_ list = [path, Path2]print (Os.path.commonprefix (p_list)    #) # Queries the common part of multiple paths Os.path.normpath (path)   # To remove redundancy from path paths. Like '/home/vamei/. /.' Converted to '/home ' print (os.path.exists)    # query file for print (os.path.getsize path)   # query file size print ( Os.path.getatime (path)  # query file last read time print (Os.path.getmtime (path))  # query file last modified time print (Os.path.isfile ( Path)    # paths are pointing to the regular file print (os.path.isdir)     # Path is pointing to the directory file
  • 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.