Link to home
Start Free TrialLog in
Avatar of skanade
skanade

asked on

Short file name to long file name?

It seems stupid to ask but I can't find a way to convert a short file name to a long file name in Delphi 3 or Win32. There is a function GetFullPathName which doesn't do the job. FindFirst seems to do it but only for the file name so I have to do more work if I want a full short name path converted to a long name path.

Am I missing something? Actually, a 16-bit application is passing the short file name on the command line to my 32-bit application and I want to get the long name right. I'll appreciate any help.

Thanks,
Sanjay
Avatar of ZifNab
ZifNab

Hi skanade,

I think that GetFullPathName normally should work.

but maybe you can try this :

Function GetLongFileName(Const FileName : String) : String;
    var
      aInfo: TSHFileInfo;
    begin
      if SHGetFileInfo(PChar(FileName),0,aInfo,Sizeof(aInfo),SHGFI_DISPLAYNAME)<>0 then
         Result:= String(aInfo.szDisplayName)
      else
         Result:= FileName;
    end;

Regards, Zif.
Avatar of skanade

ASKER

Zif,

No, it works like FindFirst only in that it returns a long name for the file name part only. What I wanted was the whole path to be converted in one shot, including all the directory components as well. Surprisingly, Win32 has a function GetShortPathName to do the reverse job but none for the short to long.

Anyway, I wrote my own parsing function which removes the tail ends, part by part to construct the whole long name with FindFirst.

Thanks,
Sanjay
ok, thanks for letting me know.
Isn't it funny that GetLongPathName is only available in Windows 98 and NT 5.0. Nice one Microsoft, we're all really impressed!
Here is the API documentation.

GetLongPathName

[This is preliminary documentation and subject to change.]

The GetLongPathName function converts the specified path to its long form. If no long path is found, this function simply returns the specified name.

DWORD GetLongPathName(
  LPCTSTR lpszShortPath,
  LPTSTR lpszLongPath,
  DWORD cchBuffer
);
 


Parameters



lpszShortPath

Pointer to a null-terminated path to be converted.

lpszLongPath

Pointer to the buffer to receive the long path. You can use the same buffer you used for the lpszShortPath parameter.

cchBuffer

Specifies the size of the buffer, in characters.



Return Values

If the function succeeds, the return value is the length of the string copied to the lpszLongPath parameter, in characters. This length does not include the terminating null character.

If lpszLongPath is too small, the function returns the size of the buffer required to hold the long path, in characters.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

QuickInfo

  Windows NT: Requires version 5.0 or later.
  Windows: Requires Windows 98 or later.
  Windows CE: Unsupported.
  Header: Declared in winbase.h.
  Import Library: Use kernel32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT.
Avatar of skanade

ASKER

philipleighs,

This is news to me and confirms my doubt. Why don't you post a line in answer so that I can give you the points.

Thanks,
Sanjay
ASKER CERTIFIED SOLUTION
Avatar of philipleighs
philipleighs

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial