Nelly Nelly - 1 year ago 164
Python Question

Is it possible to access the GetLongPathName() Win32 API in Python?

I need to convert paths in 8.3 convention to full path.
In Perl, I can use

as pointed out in How do I get full Win32 path from 8.3 DOS path with Perl? But, I need to do it in Python.

Answer Source

Use ctypes which is available in the Python standard without the need of using the pywin32 API. Like this:

from ctypes import *

buf = create_unicode_buffer(260)
GetLongPathName = windll.kernel32.GetLongPathNameW
rv = GetLongPathName(path, buf, 260)
print buf.value


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download