开发者

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

开发者 https://www.devze.com 2022-12-08 16:53 出处:网络
I need to convert paths in 8.3 convention to full path. In Perl, I can use Win32::GetLongPathName() as pointed o开发者_如何学Gout in How do I get full Win32 path from 8.3 DOS path with Perl? But, I ne

I need to convert paths in 8.3 convention to full path. In Perl, I can use Win32::GetLongPathName() as pointed o开发者_如何学Gout in How do I get full Win32 path from 8.3 DOS path with Perl? But, I need to do it in Python.


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


Use the GetLongPathName function from win32file

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

outputs:

C:\Program Files
0

精彩评论

暂无评论...
验证码 换一张
取 消