读书人

解压有关问题

发布时间: 2013-03-21 10:08:17 作者: rapoo

解压问题

[code=csharp]public static bool StartUnRAR(string rarFile, string destinationDirectory, bool deleteRarFile)
{
RegistryKey regkey;
Object regvalue;
string cmd;
ProcessStartInfo startinfo;
Process process;
string rarexe;
try
{
// 如果不输入目录则释放到与压缩包同目录下
if (destinationDirectory == null)
{
destinationDirectory = Path.GetDirectoryName(rarFile);
}



regkey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
regvalue = regkey.GetValue("");
rarexe = regvalue.ToString();
regkey.Close();
// rarexe = rarexe.Substring(1, rarexe.Length - 7);//解压缩命令,相当于在要压缩文件(rarName)上点右键->WinRAR->解压到当前文件夹
cmd = string.Format("x {0} {1} -y",
rarFile,
destinationDirectory);
startinfo = new ProcessStartInfo();
startinfo.FileName = rarexe;
startinfo.Arguments = cmd;
startinfo.WindowStyle = ProcessWindowStyle.Hidden;
process = new Process();
process.StartInfo = startinfo;
process.Start();


process.WaitForExit();

process.Close();


// 如果删除压缩文件
if (deleteRarFile)
{
if (File.Exists(rarFile))
{
File.SetAttributes(rarFile, FileAttributes.Normal);
File.Delete(rarFile);
}
}
}
catch (Exception ex)
{
Console.WriteLine("Exception during processing: {0}", ex.Message);
return false;
}

return true;
}

[/code]
[解决办法]
把这个命令行复制在控制台中运行,有什么反应?

读书人网 >C#

热点推荐