Andy Arismendi Andy Arismendi - 1 year ago 89
Python Question

How to get long file system path from python on 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

Notice the

How can I get/convert this to a full path? e.g. C:\users\administrator\appdata...

Answer Source

Please try the following code (updated):

from ctypes import create_unicode_buffer, windll
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

Hope this helps. Please refer to

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download