This library allows you to unpack RAR (version 3-5) archives, password protected and not.
MIT The code cannot be used to recreate RAR compression.
Listing files:
uses Unrar;
var rar: TRarUnpacker;
ADate: TDateTime;
ASize: Int64;
AName: String;
begin
rar := TRarUnpacker.Create('pass.rar', 'pass'); //can also be pass.exe - RAR SFX
if not rar.CheckPassword then begin
ShowMessage('Incorrect password!');
rar.Free;
Exit;
end;
while rar.NextEntry(AName, ASize, ADate) do begin
Memo1.Lines.Add(AName);
end;
rar.Free;
Extracting files:
var
rar : TRarUnpacker;
ADate: TDateTime;
ASize: Int64;
AName: String;
F : TFileStream;
OutDir, FullPath: String;
begin
OutDir := 'OutputDir\'; // destination directory
rar := TRarUnpacker.Create('pass.rar', '');
try
while rar.NextEntry(AName, ASize, ADate) do
begin
Memo1.Lines.Add(AName);
FullPath := IncludeTrailingPathDelimiter(OutDir) + AName;
ForceDirectories(ExtractFileDir(FullPath));
F := TFileStream.Create(FullPath, fmCreate);
try
rar.Extract(F);
finally
F.Free;
end;
end;
finally
rar.Free;
end;