2009-09-20 52 views
1

我壓縮目錄有子目錄,有幾個文件我不需要(在這些子目錄中),你可以修改下面的腳本,以便跳過某些我想要的文件?壓縮所有文件,但跳過一個

能支付高達$ 20到貝寶的辛勤工作:-)

procedure DoProgress(Sender: TObject; Position, Total: Integer); 
procedure DoCompressFile(Sender: TObject; const Filename: string); 

....

procedure TJvZLibMultipleMainForm.DoCompressFile(Sender:TObject;const Filename:string); 
begin 
    lblFilename.Caption := Filename; 
    Update; 
end; 

    procedure TJvZLibMultipleMainForm.btnCompressClick(Sender: TObject); 
var 
    z : TJvZlibMultiple; 
begin 
    ForceDirectories(ExtractFilePath(edFilename.Text)); 
    z := TJvZlibMultiple.Create(nil); 
    Screen.Cursor := crHourGlass; 
    try 
    lblFilename.Caption := ''; 
    pbProgress.Position := 0; 
    z.OnProgress := DoProgress; 
    z.OnCompressingFile := DoCompressFile; 
    z.CompressDirectory(edSrcFolder.Text,true,edFilename.Text); 
    finally 
    z.Free; 
    Screen.Cursor := crDefault; 
    end; 
    pbProgress.Position := 0; 
    lblFilename.Caption := 'Ready'; 
end; 


procedure TJvZLibMultipleMainForm.DoProgress(Sender: TObject; Position, Total: Integer); 
begin 
    pbProgress.Max := Total; 
    pbProgress.Position := Position; 
    Update; 
end; 
+1

@Tom:沒有必要在這裏付錢,但它是有禮貌的投票答案,你覺得有用的,就像你在這裏接受的那個:http://stackoverflow.com/questions/1448744/easy-way-修改進度條在現有的delphi代碼/ 1449129#1449129 – Argalatyr 2009-09-20 14:09:00

回答

1

如何荏苒整個目錄,然後從ZIP刪除這些文件?當然效率不高,但它完成了工作。

I use TZipMaster,並做了類似的事情。它是一個可視化組件,但也可以用作運行時組件。它是開源的。

2

你必須步行到目錄和任何子目錄和搜索所有的文件名。 任何文件名或文件擴展名與'不壓縮'列表比較,如果文件名不在該列表上,則將其添加到使用TJvZlibMultiple.AddFile的zip文件中。

6

在沒有爲JVCL TJvZlibMultiple組件真正的文檔,JVCL的源代碼的審查表明,有在TJvZlibMultiple的水平,可用於防止系統的壓縮和解*所有*沒有設置目錄中的文件(!)。它似乎甚至不可能通過文件過濾器(如「* .PAS」)。

的TJvZlibMultiple對象確實包括一些通知掛鉤,如OnCompressingFile,這僅僅是壓縮文件之前調用,但該驅動邏輯不測試從處理程序(這實際上是一個過程的任何返回.. ),因此我們不能使用此設備來表示文件應該懷疑。

鑑於這種情況,你只剩下三個主要選項:

  • 通過GJ一個建議,你可以在一個較低的水平工作,並飼料中的文件進行單獨
     
    Pseudo code: 
        -manually initializing the archive 
        -iterate for each file in the directory (ies) (recursively if needed) 
         -decide if file is to be added 
         -adding it individually with the TJvZlibMultiple.AddFile() procedure 
        -close the archive 
    
    壓縮簡而言之,「no fun」:-(這實際上需要從TJvZlibMultiple中派生一個類,因爲有些程序是受保護的,而另外一些則依賴於某些私有/受保護的變量進行初始化...
  • 內置JVCL的定製版本,具體更改爲TJvZlibMultiple.pas文件 (如果你這樣做很好,那可以提交回JVCL項目的主幹線)

    Essentially the Notification events, in particular OnCompressingFile would 
    return a value, either by beying a true function (or a procedure with side 
    effect, for backward compatibilty), and such return would be tested by the 
    CompressDirectory logic, to skip files (and possibly other features such as 
    'abort', 'use an alternate file', whatever...).
  • 前處理的目錄(IES)

    by [temporarilly] moving the undesired files elsewhere. 
    (and then calling the unmodified CompressDirectory(), 
    and then moving the files back...)

沒有有效的解決方案,這些是非常有吸引力。恕我直言,中間一個可能是最快的,但是你的代碼會從官方的JVCL中分支出來,除非你努力向開源項目提交mods)

第四種選擇可能是使用替代ZIP庫,並以某種方式將其與您的用戶界面集成。

有樂趣;-)

+0

+1的詳細答案。 – Wodzu 2009-09-20 09:06:41

+0

是否可以修改腳本,以便掃描所有目錄中的特定文件並「移動」或刪除它,然後zip? – Tom 2009-09-20 11:27:32

+0

@Tom:這相當於mjv的選項3.這提出了許多問題,其中包括用於製作副本的時間量和驅動器空間。這不是一個很難實現的選項,但是mjv建議的解決方案是一個更好的設計。 – Argalatyr 2009-09-20 14:03:33

相關問題