<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