Python3 OS file / directory methods
os module provides a very rich way to deal with files and directories.Commonly used method in the following table:
|No.||Method and Description|
Test mode permission
Change the current working directory
Mark set the path for the digital signature.
Change the file owner
Change the root directory of the current process
Close the file descriptor fd
Close all file descriptors from fd_low (inclusion) to fd_high (not included), the error will be ignored
Copy the file descriptor fd
Copy a file descriptor fd to another fd2
By changing the current working directory file descriptor
Change a file's access rights to the file specified by the parameter fd, the parameter mode is file access permissions on Unix.
Change the ownership of a file, this function modifies a file's user ID and group ID, the file specified by the file descriptor fd.
Forced writing file to disk, the file specified by the file descriptor fd, but does not enforce the update file status information.
os.fdopen (fd [, mode [, bufsize]])
Create a file object file descriptor fd, and returns the file object
Returns an open file system configuration information. Value name to retrieve the system configuration, it may be a string of defined system values, these names specified in many standards (POSIX.1, Unix 95, Unix 98, and others).
Returns the file descriptor fd state, like stat ().
Returns information file contains the file descriptor fd of the file system, such as statvfs ()
Force the file descriptor fd of the file is written to the hard disk.
Clipping file descriptor fd corresponding file, so it can not exceed the maximum file size.
Returns the current working directory
Return Unicode objects in a current working directory
If the file descriptor fd is open, and connected with the tty (-like) device, it returns true, otherwise False.
Mark set the path for the digital signature, similar chflags (), but no soft links
Modify the connection file permissions
Change the file owner, similar chown, but do not follow links.
Create a hard link named parameter dst, src pointing parameters
Returns a list of files or file folder that contains the specified path of the folder name.
Setting the file descriptor fd current position pos, how modify: pos SEEK_SET 0 Setup from the File or the beginning of the calculation; SEEK_CUR or 1 from the current position calculation; os.SEEK_END or two from the end of the file began in unix, Windows. effective
Like stat (), but no soft links
Extraction device major number from a raw device number (using stat in st_dev or st_rdev field).
In major and minor device number consisting of a number of original equipment
Recursive folder creation function. Like mkdir (), but all intermediate-level folders that you create needs to include subfolders.
Extraction device minor number from a raw device number (using stat in st_dev or st_rdev field).
In digital mode the mode to create a folder named path. The default mode is 0777 (octal).
Create a named pipe, mode to digital, the default is 0666 (octal)
os.mknod (filename [, mode = 0600 , device])
Open a file and set the desired options open, mode parameter is optional
Open a new pseudo-terminal pair. Back pty and tty file descriptor.
Returns relevant documents the system configuration information.
Create a pipe. Returns a pair of file descriptors (r, w) respectively to read and write
os.popen (command [, mode [, bufsize]])
Open a command from a pipeline
Read from the file descriptor fd up to n bytes and returns a string containing the bytes read, the corresponding file descriptor fd has reached the end, returns an empty string.
Returns the soft link points to a file
Remove the path for the path of the file. If the path is a folder, will throw OSError; see below rmdir () deletes a directory.
Recursively delete the directory.
Rename files or directories from src to dst
Recursively rename the directory, the file can also be renamed.
Remove empty directory path specified, if the directory is not empty, then throw a OSError exception.
Get path specified information, functionally equivalent to the C API in the stat () system call.
Gets the path of the file system statistics
Create a soft link
The process returns to the terminal fd (a os.open returned by the open () file descriptor) associated with the group
Process group setting terminal fd (consisting os.open returned () open file descriptors) associated to pg.
Returns a unique pathname for creating temporary files.
It returns an open mode (w + b) file object. This object does not have a file folder entry, no file descriptor will be automatically deleted.
To create a temporary file returns a unique path
It returns a string that represents the file descriptor fd is associated with a terminal device. If fd is not associated with a terminal device, an exception is thrown.
Delete the file path
Back to access and modify the file path specified time.
os.walk (top [, topdown = True [, onerror = None [, followlinks = False]]])
Output folder by the file name in the tree walk, up or down.
The string is written to the file descriptor fd. Returns the actual length of the string is written