Python3 os.pathconf() Method
Python3 OS File/Directory Methods
Overview
The os.pathconf() method returns system configuration information for an open file.
Available on Unix platforms.
Syntax
The **fpathconf()** method syntax is as follows:
os.fpathconf(fd, name)
Parameters
-
fd -- The file descriptor
-
name -- The system configuration value to retrieve; it may be a string defining a system value, and these names are specified in many standards (POSIX.1, Unix 95, Unix 98 and others). Some platforms also define extra names. These names are in the pathconf_names dictionary on the host operating system. For configuration variables not in pathconf_names, passing a number as the name is also acceptable.
Return Value
Returns the system information of the file.
Example
The following example demonstrates the use of the fpathconf() method:
#!/usr/bin/python3
import os, sys
# Open file
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )
print ("%s" % os.pathconf_names)
# Get maximum file connections
no = os.fpathconf(fd, 'PC_LINK_MAX')
print ("Maximum number of links to the file. :%d" % no)
# Get maximum filename length
no = os.fpathconf(fd, 'PC_NAME_MAX')
print ("Maximum length of a filename :%d" % no)
# Close file
os.close( fd)
print ("关闭文件成功!!")
The output of the above program is:
关闭文件成功!!