Board index » delphi » Drag & Drop Problem with long filenames

Drag & Drop Problem with long filenames

Im using Delphi 2 and Windows 98. When I drop datafiles to my
application in the explorer it starts and gives me a 16 bit filename
(e.g. "FooFil~1" instead of "FooFilename") in the command line. How can
I come around that, or how can I convert the short filename to a long
filename?
Thank you
Johannes
 

Re:Drag & Drop Problem with long filenames


You can use the GetFullPathName API function to convert from SFN to LFN like
this:

function SFN2LFN(Filename: string): string; { Short file name to long file
name }
var
  Buf1, Buf2, Buf3: PChar;
  CA1, CA2, CA3: array[0..1023] of char;
begin
  Buf1 := CA1;
  Buf2 := CA2;
  Buf3 := CA3;
  GetFullPathName(StrPCopy(Buf1, ExtractFileName(Filename)), 1024,
StrPCopy(Buf2, ExtractFilePath(Filename)), Buf3);
  Result := StrPas(Buf2);
end;

HTH,

Cameron
_______________________
cameronm...@hotmail.com

Quote
Johannes Unnewehr wrote in message <36D12F32.D0B5D...@gmx.net>...
>Im using Delphi 2 and Windows 98. When I drop datafiles to my
>application in the explorer it starts and gives me a 16 bit filename
>(e.g. "FooFil~1" instead of "FooFilename") in the command line. How can
>I come around that, or how can I convert the short filename to a long
>filename?
>Thank you
>Johannes

Re:Drag & Drop Problem with long filenames


The message <36D12F32.D0B5D...@gmx.net>
  from  Johannes Unnewehr <jou...@gmx.net> contains these words:

Quote
> Im using Delphi 2 and Windows 98. When I drop datafiles to my
> application in the explorer it starts and gives me a 16 bit filename
> (e.g. "FooFil~1" instead of "FooFilename") in the command line. How can
> I come around that, or how can I convert the short filename to a long
> filename?
> Thank you

Hi Johannes,

I had the same problem. GetFullPathname did not fix this for me.  
Here is what I did:-

{==================
 Get Long File Path
 ==================}
Function GetLongFilePath(const FileName : String):string;
var ShellFolder : IShellFolder ;
    DispName  : array [0..MAX_PATH] of widechar;
    PEaten    : Ulong;
    PIdList   : PitemIdList;
    PAttrib   : Ulong;
    StrReturn : TStrRet;
begin
{Obtain a pointer to an IshellFolder Interface}
ShellFolder := CreateComObject(CLSID_ShellDesktop) as IShellFolder;
StringToWideChar(FileName,DispName,MAX_PATH);
ShellFolder.ParseDisplayName(Application.Handle, nil, DispName,
                             PEaten,PIdList,PAttrib);
ShellFolder.GetDisplayNameOf(PidList,SHGDN_FORPARSING,StrReturn);
Result:=String(StrReturn.cStr);
end;

You will need to add the following to your uses clause:- Shlobj,ComObj;

The function will convert any fully qualified file name (short,long
or a mixture) to a long filename path where all of the names are in
long form.

--
regards

Andreas

Other Threads