Как получить длинный путь из короткого?
function ShortToLongFileName( FileName: string ): string;
var
KernelHandle: THandle;
FindData: TWin32FindData;
Search: THandle;
GetLongPathName: function( lpszShortPath: PChar; lpszLongPath: PChar;
cchBuffer: DWORD ): DWORD; stdcall;
begin
KernelHandle := GetModuleHandle( 'KERNEL32' );
if KernelHandle <> 0 then
@GetLongPathName := GetProcAddress( KernelHandle, 'GetLongPathNameA' );
// Использование GetLongPathName доступную в windows 98 и выше чтобы
// избежать проблем доступа к путям UNC в системах NT/2K/XP
if Assigned( GetLongPathName ) then begin
SetLength( Result, MAX_PATH + 1 );
SetLength( Result, GetLongPathName( PChar( FileName ), @Result[1], MAX_PATH ) );
end
else
begin
Result := '';
while true do
begin
Search := Windows.FindFirstFile( PChar( FileName ), FindData );
if Search = INVALID_HANDLE_VALUE then Break;
Result := String( '\' ) + FindData.cFileName + Result;
FileName := ExtractFileDir( FileName );
Windows.FindClose( Search );
if Length( FileName ) <= 2 then Break;
end;
Result := ExtractFileDrive( FileName ) + Result;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Caption := ShortToLongFileName( 'D:\PROGRA~1\' );
end; |