Solved

Short file name to long file name?

Posted on 1998-11-05
6
1,355 Views
Last Modified: 2011-10-03
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
0
Comment
Question by:skanade
  • 2
  • 2
  • 2
6 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1345766
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.
0
 

Author Comment

by:skanade
ID: 1345767
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
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1345768
ok, thanks for letting me know.
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 3

Expert Comment

by:philipleighs
ID: 1345769
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.
0
 

Author Comment

by:skanade
ID: 1345770
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
0
 
LVL 3

Accepted Solution

by:
philipleighs earned 50 total points
ID: 1345771
Sure no problem,

Cheers,
Phil.

0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question