Board index » delphi » Please Help: Converting short filenames to long ones in Windows95

Please Help: Converting short filenames to long ones in Windows95

Hi,

Does anybody know how to convert a full short filename (including path) to
a long filename (including path).
I've tried using the FindFirstFile() API but it only does the trick for the
filename part.
Any ideas ??

Please reply to the newsgroup.

TIA,
Alon Yaffe
========

 

Re:Please Help: Converting short filenames to long ones in Windows95


On Sat, 1 Mar 1997 20:12:54 GMT, "Alon Yaffe" <ya...@actcom.co.il>
wrote:

Quote
>Does anybody know how to convert a full short filename (including path) to
>a long filename (including path).
>I've tried using the FindFirstFile() API but it only does the trick for the
>filename part.

{ Recursively expand a short file name to a long file name. }
function ExpandShortName(const ShortName: string): string;
var
  FindData: TWin32FindData;
  Handle: THandle;
  Path, Tail: string;
begin
  Path := ExtractFilePath(ShortName);
  Tail := ExtractFileName(ShortName);
  if Tail = '' then
    { Just the drive, e.g., D:\, so nothing to expand. }
    Result := ShortName
  else
  begin
    { strip the trailing backslash, prior to expanding the directory.}
    if (Length(Path) > 0) and (Path[Length(Path)] = '\') then
      Delete(Path, Length(Path), 1);
    Path := ExpandShortName(Path);
    { Retstore the backslash, to append the file name. }
    if (Length(Path) > 0) and (Path[Length(Path)] <> '\') then
      AppendStr(Path, '\');
    { Get the base file name. }
    Handle := FindFirstFile(PChar(Path + Tail), FindData);
    if Handle = Invalid_Handle_Value then
      { File does not exist, so keep the short name. }
      Result := Path + Tail
    else
      try
        Result := Path + FindData.cFilename;
      finally
        WinProcs.FindClose(Handle);
      end;
  end;
end;

{ Get the long file name for a short name. }
function GetLongFilename(ShortName: string): string;
begin
  Result := ExpandShortName(ExpandFileName(ShortName));
end;

--
Ray Lischner, Tempest Software, Inc., Corvallis, Oregon, USA
Author of Secrets of Delphi 2 (http://www.tempest-sw.com/secrets/)

Re:Please Help: Converting short filenames to long ones in Windows95


On Sat, 1 Mar 1997 20:12:54 GMT, "Alon Yaffe" <ya...@actcom.co.il>
wrote:

Quote
>Does anybody know how to convert a full short filename (including path) to
>a long filename (including path).
>I've tried using the FindFirstFile() API but it only does the trick for the
>filename part.
>Any ideas ??

Try doing FindFirstFile for every directory in the filename too. I
know, it isn't pretty, but it'll probably work.

Re:Please Help: Converting short filenames to long ones in Windows95


On Sat, 12 Apr 1997 15:29:02 GMT, "Alon Yaffe" <ya...@actcom.co.il>
wrote:

Quote
>Does anybody know how to convert a full short filename (including path) to
>a long filename (including path).
>I've tried using the FindFirstFile() API but it only does the trick for the
>filename part.

Try DejaNews. I posted a solutions a few times in the past several
months. The solution I posted uses FindFirst recursively to expand all
the directory names.
--
Ray Lischner            
Author of Secrets of Delphi 2 (http://www.tempest-sw.com/secrets/)

Re:Please Help: Converting short filenames to long ones in Windows95


dortmund, stardate 9367.04,

 AY> Hi,

 AY> Does anybody know how to convert a full short filename (including path)
 AY> to a long filename (including path).
 AY> I've tried using the FindFirstFile() API but it only does the trick for
 AY> the filename part.
 AY> Any ideas ??

there was an article about that (by Jeffrey Richter) in the May Microsoft  
System Journal. i don't have the MJS around right now, but i'll post more  
details later, if desired.

cu
marc

-+- Let Joy and Innocence Prevail
## CrossPoint v3.11 ##

Re:Please Help: Converting short filenames to long ones in Windows95


Please take part of my exellent routine :)

No guarantees are given and I haven't tested it on a network (i.e
"\\NetworkServer\Drive_C\Command.com") although it's written with this
in mind.
This routine (as is) requires that the file exists. Feel free to
modify (and to send the new and better one as a reply to this
message).

Hope this will help you.

/Alexander <alexan...@scarptor.se>

{******************************************}

function TMainForm.TrueName(s: String): String;
var SearchRec: TSearchRec;
    TrueFileName: String;
    i: Integer;
begin
  s := ExpandUNCFileName(s);
  if s[2] = ':' then
    s[1] := UpCase(s[1])
  else
    if Copy(s, 1, 2) = '\\' then begin
      Delete(s, 1, 2);
      TrueFileName := '\\';
    end else
      TrueFileName := '';
  i := Pos('\', s);
  if i > 0 then begin
    TrueFileName := TrueFileName + Copy(s, 1, i);
    Delete(s, 1, i);
    i := Pos('\', s);
    while i > 0 Rec);
      end else begin
        TrueName := '';
        FindClose(SearchRec);
        Exit;
      end;
      i := Pos('\', s);
    end;
    if FindFirst(TrueFileName + s, faReadOnly + faHidden + faSysFile +
                 faArchive, SearchRec) = 0 then
      TrueFileName := TrueFileName + SearchRec.Name
    else
      TrueFileName := '';
    FindClose(SearchRec);
  end else
    TrueFileName := '';
  TrueName := TrueFileName;
end;

{******************************************}

On Wed, 21 May 1997 16:58:26 GMT, "Alon Yaffe" <ya...@actcom.co.il>
wrote:

Quote
>Hi,

>Does anybody know how to convert a full short filename (including path) to
>a long filename (including path).
>I've tried using the FindFirstFile() API but it only does the trick for the
>filename part.
>Any ideas ??

>Please reply to the newsgroup.

>TIA,
>Alon Yaffe
>========

Re:Please Help: Converting short filenames to long ones in Windows95


Hey! I found an API function called GetFullPathName! Look it up! :-D

(Thank you, Alon)

/Alexander

On Wed, 21 May 1997 16:58:26 GMT, "Alon Yaffe" <ya...@actcom.co.il>
wrote:

Quote
>Hi,

>Does anybody know how to convert a full short filename (including path) to
>a long filename (including path).
>I've tried using the FindFirstFile() API but it only does the trick for the
>filename part.
>Any ideas ??

>Please reply to the newsgroup.

>TIA,
>Alon Yaffe
>========

Other Threads