[英]How to get long file system path from python on Windows
This returns me a short path (DOS convention) (on Windows): 这为我返回了一条短路径(DOS约定)(在Windows上):
import tempfile
tempDir = tempfile.mkdtemp()
print tempDir
Output >>> c:\users\admini~1\appdata\local\temp\tmpf76unv
Notice the admini~1
. 注意admini~1
。
How can I get/convert this to a full path? 如何获取/转换为完整路径? eg C:\\users\\administrator\\appdata... 例如C:\\ users \\ administrator \\ appdata ...
Please try the following code (updated): 请尝试以下代码(更新):
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
Hope this helps. 希望这可以帮助。 Please refer to http://mail.python.org/pipermail/python-win32/2008-January/006642.html 请参考http://mail.python.org/pipermail/python-win32/2008-January/006642.html
tempDir = win32file.GetLongPathName(tempDir)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.