The os module provides a very rich way to work with files and directories. Common methods are shown in the following table:
Serial number | Method and description |
---|---|
1 | Check permission mode. |
2 | Change the current working directory. |
3 | Set the path to be marked as a numeric marker. |
4 | Change permissions. |
5 | Change the file owner. |
6 | Change the root of the current process. |
7 | Close the file descriptor fd. |
8 | Close all file descriptors, from fd_low (included) to fd_high (not included), and errors are ignored. |
9 | Copy the file descriptor fd. |
10 | Copy one file descriptor fd to another fd2. |
11 | Change the current working directory with a file descriptor. |
12 | Change access to a file specified by parameter fd, mode is file access under Unix. |
13 | Modify the ownership of a file, a function that modifies the user ID and user group ID of a file, specified by the file descriptor fd. |
14 | Force a file to be written to disk, specified by the file descriptor fd, but does not force updates to the file's status information. |
15 | Create a file object with the file descriptor fd and return the file object. |
16 | Returns system configuration information for an open file. Name is the value configured for the retrieved system, which may be a string that defines the system values, which are specified in many standards (POSIX.1, Unix 95, Unix 98, and others). |
17 | Returns the state of the file descriptor fd, like stat(). |
18 | Returns information about the file system of the file that contains the file descriptor fd, like statvfs(). |
19 | Force a file with a file descriptor of fd to be written to the hard disk. |
20 | Crop the file descriptor fd for the file, so it can't exceed the file size at most. |
21 | Returns to the current working directory. |
22 | Returns a Unicode object for the current working directory. |
23 | If the file descriptor fd is open and connected to the tty(-like) device, true is returned, otherwise False. |
24 | Set the path to be marked as a number, similar to chflags(), but without a soft link. |
25 | Modify connection file permissions. |
26 | Change the file owner, similar to chown, but do not track the link. |
27 | Create a hard link called parameter dst, pointing to parameter src. |
28 | Returns a list of the names of the files or folders that the folder specified by path contains. |
29 | Set the file descriptor fd the current position is pos, how to modify: SEEK_SET or 0 to set the calculated pos from the file; S EEK_CUR or 1 is calculated from the current position; S EEK_END or 2 starts at the end of the file. Valid in unix, Windows. |
30 | like stat(), but without a soft link. |
31 | Extract the device's most number from the original device number (using the st_dev in st_rdev field). |
32 | Form an original device number with the major and minor device numbers. |
33 | Recursive folder creation function. like mkdir(), but all intermediate-level folders created need to contain sub-folders. |
34 | Extract the device minor number from the original device number (using the st_dev in st_rdev field). |
35 | Create a folder named path with the mode of the number mode. T he default mode is 0777 (octal). |
36 | Create a named pipe with mode as a number, defaulting to 0666 (octal). |
37 |
os.mknod(filename[, mode=0600, device])
|
38 | Open a file and set the required opening options, and the mode parameter is optional. |
39 | Open a new pseudo-terminal pair. Returns the file descriptors for pty and tty. |
40 | Returns system configuration information for the relevant file. |
41 | Create a pipeline. Returns a pair of file descriptors (r, w) to read and write, respectively |
42 | Open a pipeline from one command. |
43 | Read up to n bytes from the file descriptor fd, return a string that contains read bytes, and the file descriptor fd corresponds to the end of the file, returning an empty string. |
44 | Returns the file to which the soft link points. |
45 | Delete a file with a path. I f path is a folder, OSError is thrown; C heck out rmdir() below to remove a directory. |
46 | Recursive deletion of the directory. |
47 | Rename the file or directory, from src to dst. |
48 | Recursively change the name of the directory, or you can change the name of the file. |
49 | Delete the empty directory specified by path and throw an OSError exception if the directory is not empty. |
50 | Gets information about the path specified by path, which is equivalent to a stat() system call in the C API. |
51 |
os.stat_float_times([newvalue])
|
52 | Gets file system statistics for the specified path. |
53 | Create a soft link. |
54 | Returns the group of processes associated with terminal fd, an open file descriptor returned by os.open(). |
55 | Set the process group associated with terminal fd, an open file descriptor returned by os.open() to pg. |
56 | Returns a unique path name to create a temporary file. |
57 | Returns an open file object with an open mode of (w-b), which has no folder entry and no file descriptor and is automatically deleted. |
58 | Returns a unique path to create a temporary file. |
59 | Returns a string that represents the terminal device associated with the file descriptor fd. If fd is not associated with the terminal device, an exception is thrown. |
60 | Delete the file path. |
61 | Returns the time when the specified path file was accessed and modified. |
62 |
os.walk(top[, topdown=True[, onerror=None[, followlinks=False]]]) The file name that outputs in the folder is either up or down by walking through the tree. |
63 | Write string to file descriptor fd, returning the length of the string that was actually written |