36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
import ctypes
|
|
from typing import NamedTuple
|
|
|
|
class win32VolumeInfo(NamedTuple):
|
|
volume_name: str
|
|
filesystem_name: str
|
|
max_component_length: int
|
|
filesystem_flags: int
|
|
serial: int
|
|
|
|
def get_volume_info(path=None):
|
|
"""
|
|
Checks for long path support using GetVolumeInformation.
|
|
Returns:
|
|
win32VolumeInfo
|
|
"""
|
|
volume_name = ctypes.create_unicode_buffer(260)
|
|
filesystem_name = ctypes.create_unicode_buffer(260)
|
|
max_component_length = ctypes.c_ulong()
|
|
serial = ctypes.c_ulong()
|
|
filesystem_flags = ctypes.c_ulong()
|
|
result = ctypes.windll.kernel32.GetVolumeInformationW(
|
|
path, # Root directory of the current drive
|
|
volume_name,
|
|
260,
|
|
ctypes.byref(serial),
|
|
ctypes.byref(max_component_length),
|
|
ctypes.byref(filesystem_flags),
|
|
filesystem_name,
|
|
ctypes.wintypes.MAX_PATH
|
|
)
|
|
if not result:
|
|
return None
|
|
return win32VolumeInfo(ctypes.wstring_at(volume_name), ctypes.wstring_at(filesystem_name), max_component_length.value, filesystem_flags.value, serial.value)
|
|
print(get_volume_info())
|