Python3 os.pathconf() Method
Python3 OS File/Directory Methods
Overview
The os.pathconf()
method is used to return system configuration information for an open file.
Available on Unix platforms.
Syntax
fpathconf() method syntax is as follows:
os.fpathconf(fd, name)
Parameters
-
fd -- File descriptor
-
name -- The system configuration value to retrieve. It may be a string that defines a system value, as specified in many standards (POSIX.1, Unix 95, Unix 98, and others). Some platforms also define additional names. These names are found in the pathconf_names
dictionary on the main 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 number of links to the file
no = os.fpathconf(fd, 'PC_LINK_MAX')
print("Maximum number of links to the file. :%d" % no)
# Get maximum length of a filename
no = os.fpathconf(fd, 'PC_NAME_MAX')
print("Maximum length of a filename :%d" % no)
# Close file
os.close(fd)
print("File closed successfully!!")
Executing the above program outputs:
File closed successfully!!