如何在python中获取完整的Windows路径

arm*_*inb 3 python windows path

如何在python中将缩短的路径转换为完整路径?例如,采取这个完整的路径

C:\Test\PathToMyDirectoryWithLongName\test.txt

它变成了

C:\Test\PATHTO~\test.txt.

我该如何改造它?

fal*_*tru 7

使用win32api.GetLongPathName:

>>> win32api.GetLongPathName(r'c:\progra~1')
'c:\\Program Files'
Run Code Online (Sandbox Code Playgroud)

并且win32api.GetShortPathName:

>>> win32api.GetShortPathName(r'c:\Program Files')
'c:\\PROGRA~1'
Run Code Online (Sandbox Code Playgroud)

注意:您需要安装pywin32才能使用上述功能.