这会返回一个短路径(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)
os.path
中的许多方法,但都无法解决我的问题。 - Andy Arismendi