codekingpro/portable-devtools
114k
1from __future__ import annotations2 3 4def get_short_path_name(long_name):5 """Gets the short path name of a given long path - http://stackoverflow.com/a/23598461/200291."""6 import ctypes # noqa: PLC04157 from ctypes import wintypes # noqa: PLC04158 9 _GetShortPathNameW = ctypes.windll.kernel32.GetShortPathNameW # noqa: N80610 _GetShortPathNameW.argtypes = [wintypes.LPCWSTR, wintypes.LPWSTR, wintypes.DWORD]11 _GetShortPathNameW.restype = wintypes.DWORD12 output_buf_size = 013 while True:14 output_buf = ctypes.create_unicode_buffer(output_buf_size)15 needed = _GetShortPathNameW(long_name, output_buf, output_buf_size)16 if output_buf_size >= needed:17 return output_buf.value18 output_buf_size = needed19 20 21__all__ = [22 "get_short_path_name",23]24 