Python os.pathconf() Method

Python 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()The method syntax is as follows:

os.fpathconf(fd, name)

Parameters

  • namefd -- file descriptor

  • namename -- the system configuration value to retrieve. It may be a string defining a system value; these names are specified in many standards (POSIX.1, Unix 95, Unix 98, and others). Some platforms also define additional 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.

    Examples

    The following example demonstrates the use of the fpathconf() method:

    #!/usr/bin/python
    # -*- coding: UTF-8 -*-
    
    import os, sys
    
    # 打开文件
    fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )
    
    print "%s" % os.pathconf_names
    
    # 获取文件最大连接数
    no = os.fpathconf(fd, 'PC_LINK_MAX')
    print "Maximum number of links to the file. :%d" % no
    
    # 获取文件名最大长度
    no = os.fpathconf(fd, 'PC_NAME_MAX')
    print "Maximum length of a filename :%d" % no
    
    # 关闭文件
    os.close( fd)
    
    print "关闭文件成功!!"
    

    The output of the above program is:

    File closed successfully!!

    Python OS File/Directory Methods

    Other Extensions