Solved

Short file name to long file name?

Posted on 1998-11-05
6
1,357 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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