Python 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 |
---|---|
1 | Test mode permission |
2 | Change the current working directory |
3 | Mark set the path for the digital signature. |
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 (inclusion) 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, the parameter mode is file access permissions on Unix. |
13 | 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. |
14 | Forced writing file to disk, the file specified by the file descriptor fd, but does not enforce the 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 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). |
17 | Returns the file descriptor fd state, like stat (). |
18 | Returns information file contains the file descriptor fd of the file system, such as statvfs () |
19 | Force the file descriptor fd of the file is written to the hard disk. |
20 | Clipping file descriptor fd corresponding file, so it can not exceed the maximum file size. |
twenty one | Returns the current working directory |
twenty two | Return Unicode objects in a current working directory |
twenty three | If the file descriptor fd is open, and connected with the tty (-like) device, it returns true, otherwise False. |
twenty four | Mark set the path for the digital signature, similar chflags (), but no soft links |
25 | Modify the connection file permissions |
26 | Change the file owner, similar chown, but do not follow links. |
27 | Create a hard link named parameter dst, src pointing parameters |
28 | Returns a list of files or file folder that contains the specified path of the folder name. |
29 | 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 |
30 | Like stat (), but no soft links |
31 | Extraction device major number from a raw device number (using stat in st_dev or st_rdev field). |
32 | In major and minor device number consisting of a number of original equipment |
33 | Recursive folder creation function. Like mkdir (), but all intermediate-level folders that you create needs to include subfolders. |
34 | Extraction device minor number from a raw device number (using stat in st_dev or st_rdev field). |
35 | In digital mode the mode to create a folder named path. The default mode is 0777 (octal). |
36 | Create a named pipe, mode to digital, the default is 0666 (octal) |
37 | os.mknod (filename [, mode = 0600 , device]) |
38 | os.open (file, flags [, mode ]) Open a file and set the desired options open, mode parameter is optional |
39 | Open a new pseudo-terminal pair. Back pty and tty file descriptor. |
40 | Returns relevant documents the system configuration information. |
41 | Create a pipe. Returns a pair of file descriptors (r, w) respectively to read and write |
42 | os.popen (command [, mode [, bufsize]]) Open a command from a pipeline |
43 | 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. |
44 | Returns the soft link points to a file |
45 | Remove the path for the path of the file. If the path is a folder, will throw OSError; see below rmdir () deletes a directory. |
46 | Recursively delete the directory. |
47 | Rename files or directories from src to dst |
48 | Recursively rename the directory, the file can also be renamed. |
49 | Remove empty directory path specified, if the directory is not empty, then throw a OSError exception. |
50 | Get path specified information, functionally equivalent to the C API in the stat () system call. |
51 | os.stat_float_times ([newvalue]) |
52 | Gets the path of the file system statistics |
53 | Create a soft link |
54 | The process returns to the terminal fd (a os.open returned by the open () file descriptor) associated with the group |
55 | Process group setting terminal fd (consisting os.open returned () open file descriptors) associated to pg. |
56 | os.tempnam ([dir [, prefix] ]) Returns a unique pathname for creating temporary files. |
57 | 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. |
58 | To create a temporary file returns a unique path |
59 | 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. |
60 | Delete the file path |
61 | Back to access and modify the file path specified time. |
62 | os.walk (top [, topdown = True [, onerror = None [, followlinks = False]]]) Output folder by the file name in the tree walk, up or down. |
63 | The string is written to the file descriptor fd. Returns the actual length of the string is written |
Reference Address:
- http://kuanghy.github.io/python-os/
- http://python.usyiyi.cn/python_278/library/os.html