在我维护的代码中,我遇到了:
from ctypes.wintypes import MAX_PATH
我想将其更改为:
try:
from ctypes.wintypes import MAX_PATH
except ValueError: # raises on linux
MAX_PATH = 4096 # see comments
但我找不到任何方法从 python (os, os.path, sys...
) 获取最大文件系统路径的值 - 有标准方法还是我需要外部库?
或者在 linux 中没有类似 MAX_PATH 的东西,至少不是发行版中的标准?
try:
MAX_PATH = int(subprocess.check_output(['getconf', 'PATH_MAX', '/']))
except (ValueError, subprocess.CalledProcessError, OSError):
deprint('calling getconf failed - error:', traceback=True)
MAX_PATH = 4096
最佳答案
正确的方法是将os.pathconf
或os.fpathconf
与PC_
一起使用前缀名称:
>>> os.pathconf('/', 'PC_PATH_MAX')
4096
>>> os.pathconf('/', 'PC_NAME_MAX')
255
请注意,路径组件 的最大长度可能因目录而异,因为它取决于文件系统,因此您可能有 os.pathconf('/', 'PC_NAME_MAX' )
为 255,os.pathconf('/', 'PC_NAME_MAX')
为 12,比方说。
关于linux - 我如何在 python 中获得 unix 中的最大文件系统路径长度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32807560/