[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
ShortFileNameToLongFilename
Author : Zibadian
E-Mail : zibadian@yahoo.com
Date : September 27, 2006
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
ShortFileNameToLongFilename
Author : Zibadian
E-Mail : zibadian@yahoo.com
Date : September 27, 2006
function ShortFileNameToLongFilename(ShortFilename: string): string;
function FindBS(Current: PChar): PChar;
begin
Result := Current;
while (Result^ <> #0) and (Result^ <> '\') do
Result := CharNext(Result);
end;
function ToLongPath(AFileName: PChar): PChar;
var
CurrBS, NextBS: PChar;
Handle, L: Integer;
FindData: TWin32FindData;
Buffer: array[0..260] of Char;
begin
Result := AFileName;
if AFileName[0] = '\' then
begin
if AFileName[1] <> '\' then Exit;
CurrBS := FindBS(AFileName + 2); // skip server name
if CurrBS^ = #0 then Exit;
CurrBS := FindBS(CurrBS + 1); // skip share name
if CurrBS^ = #0 then Exit;
end else
CurrBS := AFileName + 2; // skip drive name
L := CurrBS - AFileName;
lstrcpyn(Buffer, AFileName, L + 1);
while CurrBS^ <> #0 do
begin
NextBS := FindBS(CurrBS + 1);
if L + (NextBS - CurrBS) + 1 > SizeOf(Buffer) then Exit;
lstrcpyn(Buffer + L, CurrBS, (NextBS - CurrBS) + 1);
Handle := FindFirstFile(Buffer, FindData);
if (Handle = -1) then Exit;
Windows.FindClose(Handle);
if L + 1 + lstrlen(FindData.cFileName) + 1 > SizeOf(Buffer) then Exit;
Buffer[L] := '\';
lstrcpy(Buffer + L + 1, FindData.cFileName);
Inc(L, lstrlen(FindData.cFileName) + 1);
CurrBS := NextBS;
end;
lstrcpy(AFileName, Buffer);
end;
begin
Result := string(ToLongPath(PChar(ShortFilename)));
end;
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
