如何从Windows上的Python获取长文件系统path

这给我一个短path(DOS约定)(在Windows上):

import tempfile tempDir = tempfile.mkdtemp() print tempDir Output >>> c:\users\admini~1\appdata\local\temp\tmpf76unv 

注意admini~1

我怎样才能得到/转换为完整的path? 例如C:\ users \ administrator \ appdata …

请尝试下面的代码(更新):

 from ctypes import create_unicode_buffer, windll BUFFER_SIZE = 500 buffer = create_unicode_buffer(BUFFER_SIZE) get_long_path_name = windll.kernel32.GetLongPathNameW get_long_path_name(unicode(short_path_name), buffer, BUFFER_SIZE) long_path_name = buffer.value 

希望这可以帮助。 请参阅http://mail.python.org/pipermail/python-win32/2008-January/006642.html

 tempDir = win32file.GetLongPathName(tempDir)