Python's API about local files

Source: Internet
Author: User

<title>Python's API about local files</title> Python's API about local files

#TITLE: Python api#keywords:python, file, path about local files #date:fri Jul 1 21:24:04 2016

In Python, the file operations are mainly from the OS module, the main methods are as follows:

Function Describe
Os.listdir (dirname) List directories and files under DirName
OS.GETCWD () Get Current working directory
Os.curdir Returns the current directory ('. ')
Os.chdir (dirname) Change the working directory to DirName
Os.path.isdir (name) Determine if name is a directory, name is not a directory and return false
Os.path.isfile (name) Determine if name is not a file, name does not exist and return false
Os.path.exists (name) Determine if a file or directory exists name
Os.path.getsize (name) Get file size, if name is directory return 0L
Os.path.abspath (name) Get absolute path
Os.path.normpath (PATH) Canonical Path string form
Os.path.split (name) Split file name and directory (in fact, if you use the directory completely, it will also separate the last directory as the file name, and it will not determine whether the file or directory exists)
Os.path.splitext () Detach file name and extension
Os.path.join (Path,name) Connection directory with file name or directory
Os.path.basename (PATH) Return file name
Os.path.dirname (PATH) Return file path
Os.remove (dir) #dir为要删除的文件夹或者文件路径
Os.rmdir (PATH) #path要删除的目录的路径. It should be explained that the directory deleted using Os.rmdir must be an empty directory, or the function will fail.
Os.path.getmtime (name) # Get File modification time
Os.stat (path). stmtime # Get File modification time
Os.stat (path). stctime #获取文件修改时间
Os.path.getctime (name) #获取文件的创建时间

Author:aidongsheng

created:2016-07-01 Fri 21:24

Emacs 24.5.1 (ORG mode 8.2.10)

Validate

Python's API about local files

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.