Creating Compressed (Zipped) Folder using Delphi

前端 未结 9 2203
日久生厌
日久生厌 2021-02-05 18:52

Can I create Windows XP\'s Compressed (Zipped) Folder using Delphi?

相关标签:
9条回答
  • 2021-02-05 18:54

    Take a look at this OpenSource SynZip unit. It's even faster for decompression than the default unit shipped with Delphi, and it will generate a smaller exe (crc tables are created at startup).

    No external dll is needed. Works from Delphi 6 up to XE. No problem with Unicode version of Delphi. All in a single unit.

    I just made some changes to handle Unicode file names inside Zip content, not only Win-Ansi charset but any Unicode chars. Feedback is welcome.

    0 讨论(0)
  • 2021-02-05 18:55

    According to a thread in eggheadcafe, you can use CreateFile Function with FILE_FLAG_BACKUP_SEMANTICS to create a Compressed Folder.

    For shell extensions route, take a look at Using Windows XP "Compressed Folder" shell extension to work with .zip files by Namespace Edanmo, which is written in VB.

    I just found the similar question asked on C++. Take a look at Creating a ZIP file on Windows (XP/2003) in C/C++. I have a feeling the easiest route is buying ZipForge. See Zip a file in Delphi code sample.

    0 讨论(0)
  • 2021-02-05 18:58

    You could use TurboPower Abbrevia which is now open source.

    0 讨论(0)
  • 2021-02-05 19:00

    Take a look at these:

    • File Compression
    • FSCTL_SET_COMPRESSION
    0 讨论(0)
  • 2021-02-05 19:04

    Some time ago, I've tried all of the Delphi compression libraries that I could find, and eventually I ended up using KaZip by Kiril Antonov.

    My requirements were:

    • Free;
    • Open source;
    • Native Delphi code;
    • No external dependencies (dll, exe). My most important requirement;
    • Small memory footprint;
    • Easy to use;

    I use it mainly to turn .kml files into .kmz, and it does that amazingly fast.

    Here's an example of how I use it:

    uses
      KaZip;
    
    ...
    
    // replaces a .kml file with a .kmz file
    procedure KmlToKmz(const aFileName: string);
    var
      FS: TFileStream;
      KaZip:TKaZip;
      KmzFileName:TFileName;
    begin
      KmzFileName := ChangeFileExt(aFileName, '.kmz');
      KaZip := TKaZip.Create(nil);
      try
        // create an empty zipfile with .kmz extension:
        FS := TFileStream.Create(KmzFileName, fmOpenReadWrite or FmCreate);
        try
          KaZip.CreateZip(FS);
        finally
          FS.Free;
        end;        
    
        KaZip.Open(KmzFileName); // Open the new .kmz zipfile
        KaZip.Entries.AddFile(aFileName); // add the .kml
        KaZip.Close; 
        DeleteFile(aFileName); // delete the .kml
      finally
        KaZip.Free;
      end;
    end;
    
    0 讨论(0)
  • 2021-02-05 19:05

    If you are using Delphi X2, just use TZipFile from System.Zip:

    To Zip a folder, use:

    TZipFile.ZipDirectoryContents('ZipFile.zip', 'C:\Zip\this\right\now');
    

    To Zip files, use:

    Zip := TZipFile.Create;
    try
      Zip.Open('ZipFile.zip', zmWrite);
    
      Zip.Add('FileToBeZipped.txt');
      Zip.Add('ThisWillBeCompressedAgainForSureAndBecomeSmaller.zip');
    finally
      Zip.Free;
    end
    
    0 讨论(0)
提交回复
热议问题