On 13 Jan 1997 01:17:39 GMT, "Michael Adkins" <madk...@tpgi.com.au>
wrote:
Quote
>I have what should be just a simple problem. I have a "short" path name and
>I need a function that will make this a "long" path name. Best explained by
>an example:
>c:\multi~1\mypres~1\ --> c:\multi media\my presentations\
{ 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/)