Python3 os.pathconf()方法

pathconf()方法返回有关命名的文件系统的配置信息。

语法

以下是 pathconf()方法的语法:
os.pathconf(path, name)

参数

  • path -- 这是在文件路径

  • name -- 这指定配置值来检索; 它可以是一个字符串,它是一个定义的系统值的名称;这些名称在若干标准(POSIX.1,Unix 95,Unix 98,及其他)中指定。已知的主机操作系统名称在 os.pathconf 名称词典中给出。

返回值

该方法返回一个文件系统配置信息。可用于UNIX类系统

示例

下面的例子显示 pathconf()方法的使用。
#!/usr/bin/python3

import os, sys

print ("%s" % os.pathconf_names)

# Retrieve maximum length of a filename
no = os.pathconf('a2.py', 'PC_NAME_MAX')
print ("Maximum length of a filename :%d" % no)

# Retrieve file size
no = os.pathconf('a2.py', 'PC_FILESIZEBITS') 
print ("file size in bits  :%d" % no)
当我们运行上面的程序,它会产生以下结果:
{'PC_MAX_INPUT': 2, 'PC_VDISABLE': 8, 'PC_SYNC_IO': 9, 
'PC_SOCK_MAXBUF': 12, 'PC_NAME_MAX': 3, 'PC_MAX_CANON': 1, 
'PC_PRIO_IO': 11, 'PC_CHOWN_RESTRICTED': 6, 'PC_ASYNC_IO': 10, 
'PC_NO_TRUNC': 7, 'PC_FILESIZEBITS': 13, 'PC_LINK_MAX': 0, 
'PC_PIPE_BUF': 5, 'PC_PATH_MAX': 4}
 Maximum length of a filename :255
 file size in bits : 64

上一篇: Python3文件方法 下一篇: Python3 os文件目录的方法