Path fun on Windows

Eduard-Cristian Stefan alexandrul.ct at gmail.com
Wed Jun 6 08:02:59 CDT 2012


On Wed, Jun 6, 2012 at 3:15 PM, Adrian Buehlmann <adrian at cadifra.com> wrote:
> BTW, we shouldn't reintroduce depending on win32api, but it shouldn't be
> a problem to call the Windows API directly via Python's ctypes (see
> mercurial/win32.py).

This works on my PC:

import ctypes
GetLongPathName = ctypes.windll.kernel32.GetLongPathNameW
GetLongPathName.argtypes = [ctypes.c_wchar_p,
                            ctypes.c_wchar_p,
                            ctypes.c_uint]

# path = ...

buffer = ctypes.create_unicode_buffer(GetLongPathName(path, None, 0))
exitcode = GetLongPathName(path, buffer, len(buffer))
print 'real case path:', buffer.value
print 'exit code:', exitcode

I don't know if the exit code should be validated somehow.


More information about the Mercurial-devel mailing list