Solved

Short file name to long file name?

Posted on 1998-11-05
6
1,354 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Save pdf file to other location 3 79
JSON on ISAPI REST Server using Delphi 2 229
Convert Jpg /PNG To GIF 5 118
Error E2158 compiling with Delphi XE10 Seattle 2 83
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

932 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now