是否可以在Python中访问GetLongPathName()Win32 API?

Nel*_*lly 4 python windows

我需要将8.3约定中的路径转换为完整路径.在Perl中,我可以使用如何Win32::GetLongPathName()指出在如何通过Perl从8.3 DOS路径获取完整的Win32路径?但是,我需要在Python中完成它.

jon*_*asl 7

使用ctypesPython标准中提供的,无需使用pywin32 API.像这样:

from ctypes import *

buf = create_unicode_buffer(260)
GetLongPathName = windll.kernel32.GetLongPathNameW
rv = GetLongPathName(path, buf, 260)
print buf.value
Run Code Online (Sandbox Code Playgroud)

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


Lui*_*ron 5

使用GetLongPathName函数来自win32file

import win32file
print win32file.GetLongPathName(r'C:\progra~1')
Run Code Online (Sandbox Code Playgroud)

输出:

C:\Program Files
Run Code Online (Sandbox Code Playgroud)