在我维护的代码中,我碰到了:
from ctypes.wintypes import MAX_PATH
我想将其改为如下所示:
try: from ctypes.wintypes import MAX_PATH except ValueError: # raises on linux MAX_PATH = 4096 # see comments
但我找不到任何方式来从Python获取最大文件系统path的值( os, os.path, sys...
) – 有没有一个标准的方法,或者我需要一个外部库?
或者在linux下没有类似MAX_PATH的东西,至less在发行版本中不是标准的呢?
回答
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
你可以从文件中读取这个值:
* PATH_MAX (defined in limits.h) * FILENAME_MAX (defined in stdio.h)
或者用getconf函数使用subprocess.check_output():
$ getconf NAME_MAX / $ getconf PATH_MAX /
如下例所示:
name_max = subprocess.check_output("getconf NAME_MAX /", shell=True) path_max = subprocess.check_output("getconf PATH_MAX /", shell=True)
获取值和fpath为文件设置不同的值。