2013-10-10 12 views
0

我正在使用第三方FastZip壓縮我的文件夾,當我壓縮新文件夾已存在的文件讓說abc.zip,快速Zip overwite這個舊的abc.zip,刪除舊文件和僅壓縮新文件。郵編我的文件夾,但不覆蓋現有的一個在C#

任何人都知道解決方案。

編輯 - >我自己設法做到這一點,如果有人需要解決這個問題。

using ICSharpCode.SharpZipLib.Zip; 
using ICSharpCode.SharpZipLib.Core; 

string zipfilename = "abc.zip"; // Your required zip file 
string fdrname = "abc"; 

if (!File.Exists(zipfilename)) // If file zip does not exists 
{ 
    Directory.CreateDirectory(fdrname); // Create folder with same name 
    FastZip fz = new FastZip();   // using FastZip dll 
    fz.CreateZip(zipfilename, fdrname, true, null); // create zip file (ofcourse its empty) 
} 
if (Directory.Exists(fdrname)) // delete folder which you have created (optional) 
    Directory.Delete(fdrname); 

    try 
    { 
     ZipFile zip = new ZipFile(zipfilename); // by Using ZipFile dll 
     zip.BeginUpdate(); 
     zip.Add(pathtofile); // add file path which you want to zip in abc.zip 
     zip.CommitUpdate(); 
     zip.Close(); 
    } 
    catch (Exception e) 
    { 
     Console.WriteLine((e.ToString()); 
    } 
} 

回答

2

您可以隨時手動壓縮和解之前測試文件的存在:

if (!File.Exists(filename)) 
    fastZip.CreateZip(filename, @"C:\SourceDirectory", recurse, filter); 
else 
    //exception or message 
+0

這是我在做什麼了,不過如果(File.Exists(文件名)) – abidkhan303

+0

這是你的。你想要發生什麼? –