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

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

问题描述

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

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

import tempfile
tempDir = tempfile.mkdtemp()
print tempDir

Output >>> c:usersadmini~1appdatalocal	emp	mpf76unv

注意admini~1.

如何获取/将其转换为完整路径?例如C:用户管理员应用程序数据...

How can I get/convert this to a full path? e.g. C:usersadministratorappdata...

推荐答案

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

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天全站免登陆