Python os.pathconf() Method
os.pathconf() Overview
The os.pathconf() method is used to return the system configuration information for an open file.
Available on Unix platforms.
os.pathconf() Syntax
The syntax format of the fpathconf() method is as follows.
os.fpathconf(fd, name)
os.pathconf() Parameters
- fd – File Descriptors
- name – The value of the retrieved system configuration, which is perhaps a string defining the system value, and these names are specified in many standards (POSIX.1, Unix 95, Unix 98, and others). Some platforms also define some additional names. These names are in the dictionary of pathconf_names on the main operating system. For configuration variables that are not in pathconf_names, it is acceptable to pass a number as a name.
os.pathconf() Return Value
Returns the system information of the file.
os.pathconf() Demo
The following example demonstrates the use of the fpathconf() method.
#!/usr/bin/python3
import os, sys
# open file
fd = os.open( "/root/apidemos.com.txt", os.O_RDWR|os.O_CREAT )
print ("%s" % os.pathconf_names)
# Get the maximum number of connections to a file
no = os.fpathconf(fd, 'PC_LINK_MAX')
print ("Maximum number of links to the file. :%d" % no)
# Get the maximum length of the file name
no = os.fpathconf(fd, 'PC_NAME_MAX')
print ("Maximum length of a filename :%d" % no)
os.close( fd)
print ("Close file successfully!!!")
Output: