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

I need to convert the paths to 8.3 for the full path. In Perl, I can use Win32::GetLongPathName() , as indicated in How to get the full path to Win32 from the 8.3 DOS path with Perl? But I need to do this in Python.

+4
python windows
source share
2 answers

Use ctypes , which is available in the Python standard without the need to use 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

+6
source share

Use the GetLongPathName function from win32file

 import win32file print win32file.GetLongPathName(r'C:\progra~1') 

outputs:

 C:\Program Files 
+4
source share

All Articles