2009-10-27 88 views
2

我正在寻找一个用delphi压缩和压缩的简单方法。我已经看过torry delphi的组件:http://www.torry.net/pages.php?s=99。他们似乎都能达到我想要的效果,但使用它们的一些缺点是它们都不在delphi 2009中运行,并且非常复杂,这使得我很难将它们移植到delphi 2009中。另外,他们很少,至少对我来说。我需要基本的压缩功能,而不需要使用一堆DLL的开销。我的任务将我带到FSCTL_SET_COMPRESSION,我认为这会解决问题,但不幸的是,这也无济于事。 CREATEFILE看起来很有希望,直到我尝试它产生与FSCTL_SET相同的结果...我知道在Windows上有一些有限的本地压缩功能。例如,如果右键单击某个文件或文件夹并选择 - > sendTo - >压缩文件夹,则会巧妙地创建压缩文件。我认为,如果我能够从德尔福获得这种能力,它将是一个解决方案。在一个侧面问题上,linux是否有自己的本地压缩函数,可以使用类似于这个?用delphi创建vista目录/文件的zip文件的任何函数2009

+1

这个问题是非常相似的 - 你可能会发现一些有用的答案:http://stackoverflow.com/questions/1082735/creating-compressed-zipped-folder-using-delphi – Argalatyr 2009-10-27 23:51:40

回答

4

TurboPower的优秀Abbrevia可以下载D2009 here,D2010的支持正在进行中,并已在svn according to their forum

Abbrevia曾经是一个商业(对于$$$)产品,这意味着文档相当完整。

0

我使用Zipforge。为什么将这些移植到D2009存在问题?是因为64位?

下面是一些示例代码

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; 
+0

德尔福2009年是不是64位 – jpfollenius 2009-11-17 12:44:56

0

如果你可以从德尔福“做” COM,那么你就可以利用Windows外壳程序的内置拉链能力。它给你很好的基本能力。

在VBScript中,它看起来是这样的:

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也allws您使用DotNetZip,这是一个免费下载,这确实密码加密的拉链,ZIP64,自解压文件,unicode的,跨越拉链, 和其他东西。

0

我个人使用的VCL Zip与D2009和D2010一起运行完美。它在这篇文章的时候花费120美元,但是非常简单,灵活并且最重要的是FAST。

看一看VCLZIP,如果你有兴趣

代码明智下载线索:

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

是所有你需要一个基本的拉链,你当然可以设置压缩级别,目录结构, zip流,解压缩流等等。

希望这是一些帮助。

RE

0

看看这个OpenSource SynZip unit。解压缩速度比Delphi提供的默认单位更快,并且它会生成一个较小的exe(crc表在启动时创建)。

无需外部DLL。从Delphi 6直到XE。德尔福的Unicode版本没有问题。所有在一个单位。

我只是做了一些改变,以处理Zip内容中的Unicode文件名,不仅Win-Ansi字符集,而且任何Unicode字符。欢迎反馈。

相关问题