Python3 OS
os The module provides a very rich method for processing files and directories. Commonly used 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 flags Mark the numbers. |
4 | os.chmod(path, mode) Change permissions |
5 | os.chown(path, uid, gid) Change file owner |
6 | os.chroot(path) Change the root directory of the current process |
7 | os.close(fd) Close file descriptor fd |
os.closerange(fd_low, fd_high)Close all file descriptors , from fd_low (inclusive) to fd_high (exclusive), errors will be ignored | |
os.dup(fd) Copy file descriptor fd | |
os.dup2(fd, fd2)Copy one file descriptor fd to another A fd2 | |
os.fchdir(fd)Change the current working directory through the file descriptor | |
os.fchmod(fd, mode)Change the access permissions of a file. The file is specified by the parameter fd, and the parameter mode is under Unix. File access permissions. | |
os.fchown(fd, uid, gid)Modify the ownership of a file. This function modifies the ownership of a file. User ID and user group ID, the file is specified by the file descriptor fd. | |
os.fdatasync(fd) Force the file to be written to disk, the file specified by the file descriptor fd, However, it is not mandatory to update the status information of the file. | |
os.fdopen(fd[, mode[, bufsize]])Create a file through file descriptor fd object and returns this file object | |
os.fpathconf(fd, name)Returns an open file system Configuration information. name is the value of the system configuration being retrieved, which may be a string that defines a system value. These names are specified in many standards (POSIX.1, Unix 95, Unix 98, and others). | |
os.fstat(fd)Returns the status of file descriptor fd, like stat(). | |
os.fstatvfs(fd) Returns the file system information of the file containing the file descriptor fd, like statvfs () | |
os.fsync(fd)Force the file with the file descriptor fd to be written to the hard disk. | |
os.ftruncate(fd, length)Cut the file corresponding to the file descriptor fd, so it cannot exceed the maximum File size. | |
os.getcwd()Return to the current working directory | |
os.getcwdu()Returns a Unicode object of the current working directory | |
os.isatty(fd)
| |
24 | os.lchflags(path, flags) Set the flag of the path to a digital flag, similar to chflags(), but No 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 does not follow the link. |
27 | os.link(src, dst) Create a hard link named parameter dst, pointing to parameter src |
28 | os.listdir(path) Returns a list of the names of files or folders contained in the folder specified by path. |
29 | os.lseek(fd, pos, how) Set the current position of the file descriptor fd to pos, how method Modification: SEEK_SET or 0 sets the pos calculated from the beginning of the file; SEEK_CUR or 1 calculates from the current position; os.SEEK_END or 2 starts from the end of the file. Valid in unix and Windows |
30 | os.lstat(path) Like stat(), but without soft link |
31 | os.major(device) Extract the device major number from the original device number (use the st_dev or st_rdev field in stat). |
32 | os.makedev(major, minor) Use the major and minor device numbers to form an original device number |
33 | os.makedirs(path[, mode]) Recursive folder creation function. Like mkdir(), but all intermediate-level folders created need to contain subfolders. |
34 | os.minor(device) Extract the device minor number from the original device number (use st_dev in stat or st_rdev field). |
35 | os.mkdir(path[, mode]) Create a file named path with the mode of numeric mode folder. The default mode is 0777 (octal). |
36 | os.mkfifo(path[, mode]) Create a named pipe, mode is a number, the default is 0666 ( Octal) |
37 | os.mknod(filename[, mode=0600, device]) |
38 | os.open(file, flags[, mode]) Open a file and set the required The open option, 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 the system configuration information of related files. |
41 | os.pipe() Creates a pipe. Returns a pair of file descriptors (r, w) respectively. Read and write |
42 | os.popen(command[, mode[, bufsize]]) Open a command from a command Pipe |
43 | os.read(fd, n) Read up to n bytes from the file descriptor fd, and return a string containing the read bytes. The file corresponding to the file descriptor fd has reached the end, and an empty string is returned. |
44 | os.readlink(path) Returns the file pointed to by the soft link |
45 | os.remove(path) Delete the file with path path. If path is a folder, OSError will be thrown; see rmdir() below to delete a directory. |
46 | os.removedirs(path) Recursively delete directories. |
47 | os.rename(src, dst) Rename a file or directory from src to dst |
48 | os.renames(old, new) Recursively rename directories and files. |
49 | os.rmdir(path) Delete the empty directory specified by path. If the directory is not empty, throw a OSError exception. |
50 | os.stat(path) Gets information about the path specified by path. The function is equivalent to stat in the C API () system call. |
51 | os.stat_float_times([newvalue]) |
52 | os.statvfs(path) Get file system statistics for the specified path |
os.symlink(src, dst)Create a soft link | |
os .tcgetpgrp(fd)Returns the process group associated with the terminal fd (an open file descriptor returned by os.open()) | |
os.tcsetpgrp(fd, pg)Sets the process group associated with terminal fd (an open file descriptor returned by os.open()) to pg. | |
os.tempnam([dir[, prefix]])Returns the unique pathname used to create temporary files . | |
os.tmpfile()Returns a file object with an open mode of (w+b). This file The object has no folder entry or file descriptor and will be automatically deleted. | |
os.tmpnam()Returns a unique path to create a temporary file | |
os.ttyname(fd)Returns a string representing the terminal device associated with file descriptor fd. If fd is not associated with the terminal device, an exception is raised. | |
os.unlink(path)Delete file path | |
os.utime(path, times) | Returns the access and modification time of the specified path file. |
os.walk(top[, topdown=True[, onerror=None[, followlinks=False]]]) | Output the file names in the folder by walking in the tree, up or down. |
os.write(fd, str) | Write the string to the file descriptor fd. Return the actual write Input string length |