win32api -- long vs short filenames
jdnier at execpc.com
Tue Aug 10 00:10:46 CEST 1999
David Niergarth <jdnier at execpc.com> wrote in message
news:7oa0n0$72n at newsops.execpc.com...
> I'm trying to expand a mangled DOS 8+3 name (from WinNT4.0) into the long
> version of the name. There's a win32api function for doing the opposite,
> >>> win32api.GetShortPathName(r'c:\long_path_name\long_file_name.txt')
> But I can't figure out how to expand a mangled name into the original long
> name. Any ideas?
> --David Niergarth
David Asher (thanks, by the way) pointed me to win32api.FindFiles(), as in
This returns the long version of the last component of the path that you
feed it but not the long version of the entire path, which is what I'm
after. In case anybody is interested, here's a function that will return the
long version of the entire path from either a mangled absolute path or a
mangled simple file name in Python's current directory.
"""Transform a mangled 8+3 pathname to original long name.
pathname -- Can be an absolute path or a simple file or direcotry name
if it exists in Python's notion of the current directory.
If a simple file or directory name cannot be resolved or an absolute
path cannot be found, the original pathname will be silently returned.
import os, win32api
abspath = pathname
cur_dir = os.getcwd()
newpath = os.path.join(cur_dir, pathname)
abspath = newpath
return pathname # could not resolve relative path
pieces = 
head, tail = os.path.split(abspath)
longtail = win32api.FindFiles(os.path.join(head, tail))[-2]
return pathname # could not find path
head, tail = os.path.split(head)
return apply(os.path.join, pieces)
Seems like there should be an easier way, but this works for me.
More information about the Python-list