os module provides a very rich way to handle files and directories. Commonly used method in the following table:
No. | Method and Description |
---|---|
1 | Test mode permission |
2 | Change the current working directory |
3 | Flag is set to the path numerals. |
4 | Change Permissions |
5 | Change the file owner |
6 | Change the root directory of the current process |
7 | Close the file descriptor fd |
8 | os.closerange(fd_low, fd_high) Close all file descriptors, from fd_low (included) to fd_high (not included), the error will be ignored |
9 | Copy the file descriptor fd |
10 | Copy a file descriptor fd to another fd2 |
11 | By changing the current working directory file descriptor |
12 | Change a file's access rights to the file specified by the parameter fd, parameter mode is file access permissions under Unix. |
13 | Change the ownership of a file, a file to modify the function of user ID and user group ID, the file specified by the file descriptor fd. |
14 | Forced to write files to disk, the file specified by the file descriptor fd, but do not force an update file status information. |
15 | os.fdopen(fd[, mode[, bufsize]]) Create a file object file descriptor fd, and returns the file object |
16 | Returns an open file system configuration information. Value configured for the system name retrieved, it may be a string value defined in the system, many of these names specified in the standards (POSIX.1, Unix 95, Unix 98, and others). |
17 | 返回文件描述符fd的状态,像stat()。 |
18 | 返回包含文件描述符fd的文件的文件系统的信息,像 statvfs() |
19 | 强制将文件描述符为fd的文件写入硬盘。 |
20 | 裁剪文件描述符fd对应的文件, 所以它最大不能超过文件大小。 |
21 | 返回当前工作目录 |
22 | 返回一个当前工作目录的Unicode对象 |
23 | 如果文件描述符fd是打开的,同时与tty(-like)设备相连,则返回true, 否则False。 |
24 | 设置路径的标记为数字标记,类似 chflags(),但是没有软链接 |
25 | 修改连接文件权限 |
26 | 更改文件所有者,类似 chown,但是不追踪链接。 |
27 | 创建硬链接,名为参数 dst,指向参数 src |
28 | 返回path指定的文件夹包含的文件或文件夹的名字的列表。 |
29 | 设置文件描述符 fd当前位置为pos, how方式修改: SEEK_SET 或者 0 设置从文件开始的计算的pos; SEEK_CUR或者 1 则从当前位置计算; os.SEEK_END或者2则从文件尾部开始. 在unix,Windows中有效 |
30 | 像stat(),但是没有软链接 |
31 | 从原始的设备号中提取设备major号码 (使用stat中的st_dev或者st_rdev field)。 |
32 | 以major和minor设备号组成一个原始设备号 |
33 | 递归文件夹创建函数。像mkdir(), 但创建的所有intermediate-level文件夹需要包含子文件夹。 |
34 | 从原始的设备号中提取设备minor号码 (使用stat中的st_dev或者st_rdev field )。 |
35 | 以数字mode的mode创建一个名为path的文件夹.默认的 mode 是 0777 (八进制)。 |
36 | 创建命名管道,mode 为数字,默认为 0666 (八进制) |
37 | os.mknod(filename[, mode=0600, device]) |
38 | 打开一个文件,并且设置需要的打开选项,mode参数是可选的 |
39 | 打开一个新的伪终端对。返回 pty 和 tty的文件描述符。 |
40 | 返回相关文件的系统配置信息。 |
41 | 创建一个管道. 返回一对文件描述符(r, w) 分别为读和写 |
42 | os.popen(command[, mode[, bufsize]]) 从一个 command 打开一个管道 |
43 | 从文件描述符 fd 中读取最多 n 个字节,返回包含读取字节的字符串,文件描述符 fd对应文件已达到结尾, 返回一个空字符串。 |
44 | 返回软链接所指向的文件 |
45 | 删除路径为path的文件。如果path 是一个文件夹,将抛出OSError; 查看下面的rmdir()删除一个 directory。 |
46 | 递归删除目录。 |
47 | 重命名文件或目录,从 src 到 dst |
48 | 递归地对目录进行更名,也可以对文件进行更名。 |
49 | 删除path指定的空目录,如果目录非空,则抛出一个OSError异常。 |
50 | 获取path指定的路径的信息,功能等同于C API中的stat()系统调用。 |
51 | os.stat_float_times([newvalue]) |
52 | 获取指定路径的文件系统统计信息 |
53 | 创建一个软链接 |
54 | 返回与终端fd(一个由os.open()返回的打开的文件描述符)关联的进程组 |
55 | 设置与终端fd(一个由os.open()返回的打开的文件描述符)关联的进程组为pg。 |
56 | 返回唯一的路径名用于创建临时文件。 |
57 | 返回一个打开的模式为(w+b)的文件对象 .这文件对象没有文件夹入口,没有文件描述符,将会自动删除。 |
58 | 为创建一个临时文件返回一个唯一的路径 |
59 | 返回一个字符串,它表示与文件描述符fd 关联的终端设备。如果fd 没有与终端设备关联,则引发一个异常。 |
60 | 删除文件路径 |
61 | 返回指定的path文件的访问和修改的时间。 |
62 | os.walk(top[, topdown=True[, οnerrοr=None[, followlinks=False]]]) 输出在文件夹中的文件名通过在树中游走,向上或者向下。 |
63 | 写入字符串到文件描述符 fd中. 返回实际写入的字符串长度 |
64 | 获取文件的属性信息。 |