We help IT Professionals succeed at work.
Get Started

Delphi zipping files using KAZip - how do i add it to the existing code i have

Garydene
Garydene asked
on
2,129 Views
Last Modified: 2013-11-23
Delphi - zipping files using KAZip

i need to zip the files. So i have decided to add zipping procedure in the Delph exe i am calling from javascript.
Can someone assist me to add in the lines of code i need to tell Delpi to use KAZIP and to create a zip file called Mirczip and add the contents of the 'C:\send2Mirc\casebin\ to it.


 program Project2;

uses
  SysUtils, Classes, Dialogs,
  IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdHTTP;

{$R *.res}

var
    fs : tfilestream;
    xx : widestring;
    dirname : string;
    zipfile : string;

procedure DoPost;
var
  IdHTTP1: TIdHTTP;
begin
  IdHTTP1:= TIdHTTP.Create(nil);
  try
    dirname:= 'C:\send2Mirc\casebin\';
    zipfile:= dirname + '\Mirczip.zip';
    fs:=tfilestream.create(zipfile,fmOpenRead);
    IdHTTP1.Request.ContentType:='application/x-zip-compressed';
    IdHTTP1.Request.BasicAuthentication := True;
    IdHTTP1.Request.Username:='username';
    IdHTTP1.Request.Password:='password';
    showmessage('Posting now file -> ' + zipfile )  ;
    xx:=IdHTTP1.Post('http://10.0.1.1:8080/TeachFile/zip?overwrite=no',fs);
    showmessage(xx);
    IdHTTP1.Free;
  except
    on e: exception do
    begin
      IdHTTP1.Free;
      if pos('Connection Closed Gracefully.',e.message)>0 then
      begin
        // it was just an exception that must be trapped or compiled version will crash
      end
      else
      begin
        // just continue on without interruption
      end;
    end;
  end;
end;

begin
  DoPost;
end.
 
Comment
Watch Question
Top Expert 2010
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE