Konuyu Oyla:
  • Derecelendirme: 0/5 - 0 oy
  • 1
  • 2
  • 3
  • 4
  • 5
TZipFile
#1
Arkadaşlar kolay gelsin

Dosya sıkıştırma için TZipFile ile ilgili bir sürü örnek gördüm, fakat bende herhangi bir dosya oluşmuyor. Sebebi ne olabilir. 

var
Zip : TZipFile;
  begin
  Zip:=TZipFile.Create;
  try
   zip.Open(pansichar('D:\temp\Test.zip'), zmWrite);
   zip.Add('D:\temp\TestWeb.exe');
   zip.Close;
  except
   ShowMessage('Dosya Sıkıştırılamadı.!!.');
   exit;
  end;
  FreeAndNil(zip);
Cevapla
#2
Kullandığım kod parçacığını paylaşayım

{-------------------------------------------------------------------------------
   -Klasör Sıkıştırma  ZIP
-------------------------------------------------------------------------------}
function TfrmMain.zipFolder(ArchiveName, FilePath: String): boolean;
var Zip:TZipFile;
begin
 Zip:=TZipFile.Create;
 try

  zip.ZipDirectoryContents(ArchiveName,FilePath );

  Result:=true;
 except
  REsult:=false;
 end;
 FreeAndNil(zip);

end;

{-------------------------------------------------------------------------------
   -Dosya Sıkıştırma  ZIP
-------------------------------------------------------------------------------}
function TfrmMain.zipFile(ArchiveName, Filename: String): boolean;
var Zip:TZipFile;
begin
 Zip:=TZipFile.Create;
 try
  if FileExists(ArchiveName) then
   DeleteFile(ArchiveName);
  zip.Open(ArchiveName,zmWrite);
  zip.Add(Filename);
  zip.Close;
  Result:=true;
 except
  REsult:=false;
 end;
 FreeAndNil(zip);
end;


{-------------------------------------------------------------------------------
   -Dosya Açma UNZIP
-------------------------------------------------------------------------------}
function TfrmMain.UnZipFile(ArchiveName, Path: String): boolean;
var Zip:TZipFile;
begin

 Zip:=TZipFile.Create;
 try
   zip.Open(ArchiveName,zmRead);
   zip.ExtractAll(Path);
   zip.Close;
   result:=true;
 except
  result:=false;
 end;
 zip.Free;

end;

Klasör sıkıştırma kullanımı

  if zipFolder('c:\1\test.zip','c:\2') then
 begin
// işlem tamam
 end
 else
 begin
// işlem hatalı 
 end;

ZIP işlemleri için bu tanımlamayı unutmayınız.
uses zip;
Cevapla
#3
Teşekkürler 

problem kaynağı : pansichar  
Cevapla
#4
teşekkürler
Cevapla
#5
Bu da benden olsun, ZipForge ComponentAce komponentinin çok sade örnekleri

hk11cza.JPG
unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls, ZipForge, ComCtrls;

type
 TForm1 = class(TForm)
   Archiver: TZipForge;
   Button1: TButton;
   Button2: TButton;
   ProgressBar1: TProgressBar;
   lblFile: TLabel;
   Button3: TButton;
   Button4: TButton;
   procedure Button1Click(Sender: TObject);
   procedure Button2Click(Sender: TObject);

   procedure ZipForge1FileProgress(Sender: TObject; FileName: WideString;
     Progress: Double; Operation: TZFProcessOperation;
     ProgressPhase: TZFProgressPhase; var Cancel: Boolean);
   procedure ZipForge1OverallProgress(Sender: TObject; Progress: Double;
     Operation: TZFProcessOperation; ProgressPhase: TZFProgressPhase;
     var Cancel: Boolean);

   procedure Button3Click(Sender: TObject);
   procedure Button4Click(Sender: TObject);
 private
   { Private declarations }
 public
   { Public declarations }
 end;

var
 Form1: TForm1;

implementation

{$R *.dfm}

//- BURASI LABELİ VE PROGRESSBARI İŞLİYOR------
procedure TForm1.ZipForge1FileProgress(Sender: TObject;
 FileName: WideString; Progress: Double; Operation: TZFProcessOperation;
 ProgressPhase: TZFProgressPhase; var Cancel: Boolean);
begin
lblFile.Caption := 'Extracting: ' + FileName;
 Application.ProcessMessages;
end;

procedure TForm1.ZipForge1OverallProgress(Sender: TObject;
 Progress: Double; Operation: TZFProcessOperation;
 ProgressPhase: TZFProgressPhase; var Cancel: Boolean);
begin
 ProgressBAR1.Position := Trunc(Progress);
 Application.ProcessMessages;
end;
//-----------------------

//---------------- Only a File Zip Compress ------------
procedure TForm1.Button1Click(Sender: TObject);
begin
 try
 with archiver do
 begin
     Password:='1212';
   // Set the name of the archive file we want to create
   FileName := 'C:\test_FILE.zip';
   // Because we create a new archive,
   // we set Mode to fmCreate
   OpenArchive(fmCreate);
   // Set base (default) directory for all archive operations
   BaseDir := 'C:\';
   // Add file C:\test.txt the archive; wildcards can be used as well
   AddFiles('c:\A.XLS');
   CloseArchive();
 end;
 except
 on E: Exception do
   begin
     Writeln('Exception: ', E.Message);
     // Wait for the key to be pressed
     Readln;
   end;
 end;  
end;

//----------- Folders Zip Compress--------
procedure TForm1.Button2Click(Sender: TObject);

begin

 try
 with archiver do
 begin
   Password:='1212';
   // Set the name of the archive file we want to create
   FileName := 'C:\test_FOLDERS.zip';

   // Because we create a new archive,
   // we set Mode to fmCreate
   OpenArchive(fmCreate);

   // Set base (default) directory for all archive operations
   BaseDir := 'C:\';
   // Add the c:\Test folder to the archive with all subfolders
   AddFiles('C:\PUANTAJ\*.*');  // PUANTAJ KLASÖRÜNÜ ZİPLE

   CloseArchive();

 end;
 except
 on E: Exception do
   begin
     Writeln('Exception: ', E.Message);
     // Wait for the key to be pressed
     Readln;
   end;
 END;

 END;

//------- File Unzip Extract ----------------------
procedure TForm1.Button3Click(Sender: TObject);
begin
 try
 with archiver do
 begin
 PASSWORD:='1212';
   // The name of the ZIP file to unzip
   FileName := 'C:\test_FILE.zip';
   // Open an existing archive
   OpenArchive(fmOpenRead);
   // Set base (default) directory for all archive operations
   BaseDir := 'C:\';
   // Extract all files from the archive to C:\ folder
   ExtractFiles('*.*');
   CloseArchive();
 end;
 except
 on E: Exception do
   begin
     Writeln('Exception: ', E.Message);
     // Wait for the key to be pressed
     Readln;
   end;
 end;

end;

//-----------klasörleri  unzip extract ---------------
procedure TForm1.Button4Click(Sender: TObject);
begin
 try
 with archiver do
 begin
 PASSWORD:='1212';
   // The name of the ZIP file to unzip
   FileName := 'C:\test_FOLDERS.zip';
   // Open an existing archive
   OpenArchive(fmOpenRead);
   // Set base (default) directory for all archive operations
   BaseDir := 'C:\';
   // Extract all files from the archive to C:\ folder
   ExtractFiles('*.*');
   CloseArchive();
 end;
 except
 on E: Exception do
   begin
     Writeln('Exception: ', E.Message);
     // Wait for the key to be pressed
     Readln;
   end;
 end;
end;
END.
__________________________
From Now I will only Reading.
Cevapla




Konuyu Okuyanlar: 1 Ziyaretçi