【问题标题】:How to get long file system path from python on Windows如何在 Windows 上从 python 获取长文件系统路径
【发布时间】:2012-07-10 08:45:22
【问题描述】:

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

import tempfile
tempDir = tempfile.mkdtemp()
print tempDir

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

注意admini~1

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

【问题讨论】:

  • @Levon 我在os.path 中尝试了很多方法,但没有任何效果。
  • @AndyArismendi 为什么需要完整路径?
  • @AshwiniChaudhary 出于我的目的,我正在对第三方模块进行故障排除,并想为其提供完整路径,但没有找到“内置”方法来获得长路径,尽管我可以一些人们可能想要这个的其他原因:1)显示路径,2)当Windows 8.3 Name Creation is disabled

标签: python windows path


【解决方案1】:

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

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

【讨论】:

【解决方案2】:
tempDir = win32file.GetLongPathName(tempDir)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-30
    • 1970-01-01
    • 2011-10-02
    • 1970-01-01
    • 2015-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多