You can call the fpathconf(file_descriptor, name) function to get the system configuration information relevant to an open file. name specifies the configuration value to retrieve; it may be a string which is the name of a defined system value; these names are specified in a number of standards. Note that this function is only available on Unix systems. For example,
import os, sys # Open a file fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT ) # Now 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 # Now get maximum length of a filename no = os.fpathconf(fd, 'PC_NAME_MAX') print "Maximum length of a filename :%d" % no os.close( fd)
When we run above program, it produces following result:
Maximum number of links to the file. :127 Maximum length of a filename :255