views:

352

answers:

4

I am looking for a simple method of zipping and compressing with delphi. I have already looked at the components at torry delphi:http://www.torry.net/pages.php?s=99. They all seem as though they would accomplish what I want however a few disadvantages to using them is that none of them run in delphi 2009 and are very complex which makes it difficult for me to port them to delphi 2009. And besides, the documentation on them is scarce, well at least to me. I need basic zipping functionality without the overhead of using a bunch of DLLs. My quest lead me to FSCTL_SET_COMPRESSION which I thought would have settled the issue but unfortunately this too did not work. CREATEFILE looked promising, until I tried it yielded the same result as FSCTL_SET... I know that there are some limited native zipping capability on windows. For instance if one right clicks a file or folder and selects -> sendTo ->zipped folder, a zipped archive is smartly created. I think if I was able to access that capability from delphi it will be a solution. On a side issue, does linux have its own native zipping functions that can be used similar to this?

+4  A: 

TurboPower's excellent Abbrevia can be downloaded for D2009 here, D2010 support is underway and already available in svn according to their forum.

Abbrevia used to be a commercial (for $$$) product, which means that the documentation is quite complete.

fvu
A: 

I use Zipforge. Why are there problems porting these to D2009? Is it because of the 64bit??

Here is some sample code

procedure ZipIt;
var
  Archiver: TZipForge;
  FileName: String;
begin
    try
      Archiver:= TZipForge.create(self);
      with Archiver do begin
        FileName := 'c:\temp\myzip.zip';

        // Create a new archive file
        OpenArchive(fmCreate);

        // Set path to folder with some text files to BaseDir
        BaseDir := 'c:\temp\';

        // Add all files and directories from 'C:\SOURCE_FOLDER' to the archive
        AddFiles('myfiletozip.txt');


        // Close the archive
        CloseArchive;
      end;
    finally
      Archiver.Free;
    end;
end;
M Schenkel
Delphi 2009 is not 64-bit
Smasher
A: 

If you can "do" COM from Delphi, then you can take advantage of the built-in zip capability of the Windows shell. It gives you good basic capability.

In VBScript it looks like this:

Sub CreateZip(pathToZipFile, dirToZip)

    WScript.Echo "Creating zip  (" & pathToZipFile & ") from folder (" & dirToZip & ")"

    Dim fso
    Set fso= Wscript.CreateObject("Scripting.FileSystemObject")

    If fso.FileExists(pathToZipFile) Then
        WScript.Echo "That zip file already exists - deleting it."
        fso.DeleteFile pathToZipFile
    End If

    If Not fso.FolderExists(dirToZip) Then
        WScript.Echo "The directory to zip does not exist."
        Exit Sub
    End If

    NewZip pathToZipFile

    dim sa
    set sa = CreateObject("Shell.Application")

    Dim zip
    Set zip = sa.NameSpace(pathToZipFile)

    WScript.Echo "opening dir  (" & dirToZip & ")"

    Dim d
    Set d = sa.NameSpace(dirToZip)


    For Each s In d.items
        WScript.Echo  s
    Next

    ' http://msdn.microsoft.com/en-us/library/bb787866(VS.85).aspx
    ' ===============================================================
    ' 4 = do not display a progress box
    ' 16 = Respond with "Yes to All" for any dialog box that is displayed.
    ' 128 = Perform the operation on files only if a wildcard file name (*.*) is specified. 
    ' 256 = Display a progress dialog box but do not show the file names.
    ' 2048 = Version 4.71. Do not copy the security attributes of the file.
    ' 4096 = Only operate in the local directory. Don't operate recursively into subdirectories.

    WScript.Echo "copying files..."

    zip.CopyHere d.items, 4

    ' wait until finished
    sLoop = 0
    Do Until d.Items.Count <= zip.Items.Count
        Wscript.Sleep(1000)
    Loop

End Sub

COM also allws you to use DotNetZip, which is a free download, that does password-encrypted zips, zip64, Self-extracting archives, unicode, spanned zips, and other things.

Cheeso
A: 

Personally I use VCL Zip which runs with D2009 and D2010 perfectly fine. it does cost $120 at the time of this post but is very simple, flexible and most of all FAST.

Have a look at VCLZIP and download the trail if your interested

code wise:

VCLZip1.ZipName := ‘myfiles.zip’;
VCLZip1.FilesList.add(‘c:\mydirectory\*.*’);
VCLZip1.Zip;

is all you need for a basic zip, you can of course set compression levels, directory structures, zip streams, unzip streams and much more.

Hope this is of some assistance.

RE

Reallyethical