如何在Windows上从python获取长文件系统路径 [英] How to get long file system path from python on Windows

查看:157
本文介绍了如何在Windows上从python获取长文件系统路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这为我返回了一条短路径(DOS约定)(在Windows上):

This returns me a short path (DOS convention) (on Windows):

import tempfile
tempDir = tempfile.mkdtemp()
print tempDir

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

注意admini~1.

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

How can I get/convert this to a full path? e.g. 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

希望这会有所帮助.请参考 http://mail.python.org/pipermail /python-win32/2008-January/006642.html

Hope this helps. Please refer to http://mail.python.org/pipermail/python-win32/2008-January/006642.html

这篇关于如何在Windows上从python获取长文件系统路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆