Sample code for 30+ languages & platforms
Delphi DLL

Extract Only Newer Files Using UnzipNewer

See more Zip Examples

This example demonstrates how to use the UnzipNewer method to extract only those ZIP entries that are newer than existing files already present on disk.

This is useful for:

  • Updating previously extracted ZIP contents
  • Avoiding unnecessary overwriting of unchanged files
  • Incremental deployment or synchronization scenarios
  • Faster extraction when many files are already up-to-date

Suppose the ZIP archive contains:

docs/readme.txt
images/logo.png
data/config.json

And suppose the target extraction directory already contains:

c:/temp/app/docs/readme.txt
c:/temp/app/images/logo.png

If the ZIP version of docs/readme.txt is newer than the existing file on disk, it will be extracted and overwrite the existing file.

If the existing images/logo.png file is already newer or has the same timestamp, it will not be overwritten.

Files that do not yet exist on disk are extracted normally.

The UnzipNewer method returns the number of files extracted, or -1 if the operation fails.

Chilkat Delphi DLL Downloads

Delphi DLL
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Zip;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
zip: HCkZip;
numFilesUnzipped: Integer;

begin
success := False;

zip := CkZip_Create();

// Open an existing ZIP archive.
success := CkZip_OpenZip(zip,'qa_data/zips/applicationUpdate.zip');
if (success = False) then
  begin
    Memo1.Lines.Add(CkZip__lastErrorText(zip));
    Exit;
  end;

// ------------------------------------------------------------
// Extract only ZIP entries that are newer than the
// corresponding files already existing on disk.
// 
// Existing files that are already up-to-date are skipped.
// 
numFilesUnzipped := CkZip_UnzipNewer(zip,'c:/temp/app');

if (numFilesUnzipped < 0) then
  begin
    Memo1.Lines.Add(CkZip__lastErrorText(zip));
    Exit;
  end;

Memo1.Lines.Add('Number of files extracted = ' + IntToStr(numFilesUnzipped));
Memo1.Lines.Add('');

// ------------------------------------------------------------
// Example behavior:
// 
// ZIP contains:
// 
//     docs/readme.txt
//     images/logo.png
//     data/config.json
// 
// Existing filesystem files:
// 
//     c:/temp/app/docs/readme.txt
//     c:/temp/app/images/logo.png
// 
// If the ZIP version of docs/readme.txt is newer,
// it will overwrite the existing file.
// 
// If c:/temp/app/images/logo.png is already newer,
// it will be skipped.
// 
// data/config.json will be extracted if it does not
// already exist.
// 

CkZip_CloseZip(zip);

Memo1.Lines.Add('UnzipNewer completed successfully.');

CkZip_Dispose(zip);

end;