Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get full windows path in python

How can I transform a shortened path to full path in python? For example take this full path

C:\Test\PathToMyDirectoryWithLongName\test.txt

which got transformed into

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

How do I transform it back?

like image 981
arminb Avatar asked Sep 21 '26 15:09

arminb


1 Answers

Using win32api.GetLongPathName:

>>> win32api.GetLongPathName(r'c:\progra~1')
'c:\\Program Files'

and win32api.GetShortPathName:

>>> win32api.GetShortPathName(r'c:\Program Files')
'c:\\PROGRA~1'

NOTE: You need to install pywin32 to use above functions.

like image 92
falsetru Avatar answered Sep 24 '26 04:09

falsetru