2009-10-27 59 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字符。歡迎反饋。

相關問題