測試了DotNetZip與SharpZipLib,這兩個在處理有子資料夾時,都不好處理,
也會發生有些檔案壓縮錯誤,所以改用透過7Zip來壓縮比較簡單。
//壓縮
private static void Compress(string filePath,string zipPath,string sdir)
{
Process p = new Process();
p.StartInfo.FileName = filePath;
p.StartInfo.Arguments = "a -tzip" + " " + zipPath + " " + sdir;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.WaitForExit();
p.Close();
}
//解壓縮
private static void DeCompress(string filePath, string zipPath, string ddir)
{
Process p = new Process();
p.StartInfo.FileName = filePath;
p.StartInfo.Arguments = "x" + " " + zipPath + " -o" + ddir +" -y";
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.WaitForExit();
p.Close();
}
沒有留言:
張貼留言