/// 解壓文件(不帶密碼) RAR壓縮程序 返回解壓出來的文件數量
/// </summary>
/// <param name="destPath">解壓至目錄</param>
/// <param name="rarfilePath">壓縮文件路徑</param>
public static int RARToFileEmail(string destPath, string rarfilePath)
{
try
{
//組合出需要shell的完整格式
string shellArguments = string.Format("x -o+ \"{0}\" \"{1}\\\"",
rarfilePath, destPath);
//用Process調用
using (Process unrar = new Process())
{
unrar.StartInfo.FileName = "winrar.exe";
unrar.StartInfo.Arguments = shellArguments;
//隱藏rar本身的窗口
unrar.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
unrar.Start();
//等待解壓完成
unrar.WaitForExit();
unrar.Close();
}
//統計解壓後的目錄和文件數
//string str=string.Format("解壓完成,共解壓出:{0}個目錄,{1}個文件",
// di.GetDirectories().Length, di.GetFiles().Length);
//return str;
}
catch (Exception ex)
{
return 0;
}
DirectoryInfo di = new DirectoryInfo(destPath);
int dirfileCount = 0;
foreach (System.IO.DirectoryInfo dir in di.GetDirectories())
{
dirfileCount++;
}
foreach (System.IO.FileInfo item in di.GetFiles())
{
dirfileCount++;
}
return dirfileCount;
}