10

这会返回一个短路径(DOS 约定)(在 Windows 上):

import tempfile
tempDir = tempfile.mkdtemp()
print tempDir

Output >>> c:\users\admini~1\appdata\local\temp\tmpf76unv

注意admini~1.

如何获取/将其转换为完整路径?例如 C:\users\administrator\appdata...

4

2 回答 2

10

请尝试以下代码(更新):

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

于 2012-07-10T20:03:44.513 回答
7
tempDir = win32file.GetLongPathName(tempDir)
于 2014-09-25T05:26:21.063 回答