这会返回一个短路径(DOS 约定)(在 Windows 上):
import tempfile
tempDir = tempfile.mkdtemp()
print tempDir
Output >>> c:\users\admini~1\appdata\local\temp\tmpf76unv
注意admini~1
.
如何获取/将其转换为完整路径?例如 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)