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

os.access(path, mode)

Check permission mode.
2

os.chdir(path)

Change the current working directory.
3

os.chflags(path, flags)

Set the path to be marked as a numeric marker.
4

os.chmod(path, mode)

Change permissions.
5

os.chown(path, uid, gid)

Change the file owner.
6

os.chroot(path)

Change the root of the current process.
7

os.close(fd)

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), and errors are ignored.
9

os.dup(fd)

Copy the file descriptor fd.
10

os.dup2(fd, fd2)

Copy one file descriptor fd to another fd2.
11

os.fchdir(fd)

Change the current working directory with a file descriptor.
12

os.fchmod(fd, mode)

Change access to a file specified by parameter fd, mode is file access under Unix.
13

os.fchown(fd, uid, gid)

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

os.fdatasync(fd)

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

os.fdopen(fd[, mode[, bufsize]])

Create a file object with the file descriptor fd and return the file object.
16

os.fpathconf(fd, name)

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

os.fstat(fd)

Returns the state of the file descriptor fd, like stat().
18

os.fstatvfs(fd)

Returns information about the file system of the file that contains the file descriptor fd, like statvfs().
19

os.fsync(fd)

Force a file with a file descriptor of fd to be written to the hard disk.
20

os.ftruncate(fd, length)

Crop the file descriptor fd for the file, so it can't exceed the file size at most.
21

os.getcwd()

Returns to the current working directory.
22

os.getcwdu()

Returns a Unicode object for the current working directory.
23

os.isatty(fd)

If the file descriptor fd is open and connected to the tty(-like) device, true is returned, otherwise False.
24

os.lchflags(path, flags)

Set the path to be marked as a number, similar to chflags(), but without a soft link.
25

os.lchmod(path, mode)

Modify connection file permissions.
26

os.lchown(path, uid, gid)

Change the file owner, similar to chown, but do not track the link.
27

os.link(src, dst)

Create a hard link called parameter dst, pointing to parameter src.
28

os.listdir(path)

Returns a list of the names of the files or folders that the folder specified by path contains.
29

os.lseek(fd, pos, how)

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

os.lstat(path)

like stat(), but without a soft link.
31

os.major(device)

Extract the device's most number from the original device number (using the st_dev in st_rdev field).
32

os.makedev(major, minor)

Form an original device number with the major and minor device numbers.
33

os.makedirs(path[, mode])

Recursive folder creation function. like mkdir(), but all intermediate-level folders created need to contain sub-folders.
34

os.minor(device)

Extract the device minor number from the original device number (using the st_dev in st_rdev field).
35

os.mkdir(path[, mode])

Create a folder named path with the mode of the number mode. T he default mode is 0777 (octal).
36

os.mkfifo(path[, mode])

Create a named pipe with mode as a number, defaulting to 0666 (octal).
37

os.mknod(filename[, mode=0600, device])
Create a filename file system node (file, device special file, or named pipe).

38

os.open(file, flags[, mode])

Open a file and set the required opening options, and the mode parameter is optional.
39

os.openpty()

Open a new pseudo-terminal pair. Returns the file descriptors for pty and tty.
40

os.pathconf(path, name)

Returns system configuration information for the relevant file.
41

os.pipe()

Create a pipeline. Returns a pair of file descriptors (r, w) to read and write, respectively
42

os.popen(command[, mode[, bufsize]])

Open a pipeline from one command.
43

os.read(fd, n)

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

os.readlink(path)

Returns the file to which the soft link points.
45

os.remove(path)

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

os.removedirs(path)

Recursive deletion of the directory.
47

os.rename(src, dst)

Rename the file or directory, from src to dst.
48

os.renames(old, new)

Recursively change the name of the directory, or you can change the name of the file.
49

os.rmdir(path)

Delete the empty directory specified by path and throw an OSError exception if the directory is not empty.
50

os.stat(path)

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])
Determines whether stat_result timestamp is displayed as a float object.

52

os.statvfs(path)

Gets file system statistics for the specified path.
53

os.symlink(src, dst)

Create a soft link.
54

os.tcgetpgrp(fd)

Returns the group of processes associated with terminal fd, an open file descriptor returned by os.open().
55

os.tcsetpgrp(fd, pg)

Set the process group associated with terminal fd, an open file descriptor returned by os.open() to pg.
56

os.tempnam([dir[, prefix]])

Returns a unique path name to create a temporary file.
57

os.tmpfile()

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

os.tmpnam()

Returns a unique path to create a temporary file.
59

os.ttyname(fd)

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

os.unlink(path)

Delete the file path.
61

os.utime(path, times)

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

os.write(fd, str)

Write string to file descriptor fd, returning the length of the string that was actually written