Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

windows

I need to convert paths in 8.3 convention to full path. In Perl, I can use Win32::GetLongPathName() 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.

like image 464
Nelly Avatar asked Dec 14 '22 01:12

Nelly


1 Answers

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

From http://mail.python.org/pipermail/python-win32/2008-January/006642.html

like image 158
Jonas Lejon Avatar answered Mar 09 '23 00:03

Jonas Lejon