/// <summary>/// 解压一个Rar文件/// </summary>/// <param name="RarFile">需要解压的Rar文件(绝对路径)</param>/// <param name="TargetDirectory">解压到的目录</param>/// <param name="OverWrite">是否覆盖已存在的文件</param>public static void UnRar(string RarFile, string TargetDirectory, bool OverWrite = true){//如果解压到的目录不存在,则报错if (!System.IO.Directory.Exists(TargetDirectory)){throw new System.IO.FileNotFoundException("指定的目录: " + TargetDirectory + " 不存在!");}using (var archive = SharpCompress.Archives.Rar.RarArchive.Open(RarFile)){foreach (var entry in archive.Entries){if (!entry.IsDirectory){entry.WriteToDirectory(TargetDirectory, new SharpCompress.Common.ExtractionOptions(){ExtractFullPath = true,Overwrite = OverWrite});}}}}
本机测试结果:
目前来看这种解压方式对于电脑有没有安装rar压缩软件并没有要求
(PS:我测试的电脑上安装的是7-zip,没有安装WinRaR软件)