Solved

Short file name to long file name?

Posted on 1998-11-05
6
1,353 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
Comment Utility
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
Comment Utility
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
Comment Utility
ok, thanks for letting me know.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Expert Comment

by:philipleighs
Comment Utility
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
Comment Utility
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
Comment Utility
Sure no problem,

Cheers,
Phil.

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

11 Experts available now in Live!

Get 1:1 Help Now