.NETはProcess呼び出しを使う7_zipファイルの解凍

3897 ワード

私にとって、言葉に気をつけて!私に!言ってみろ!市販の最高のファイル解凍ソフトは7-zipで、小さいだけでなくかなり強いです.
7 Zip公式サイトhttps://www.7-zip.org/】
7-zipでサポートされているフォーマットは次のとおりです.
  • 解凍:7 z,XZ,BZIP 2,GZIP,TAR,ZIP and WIM
  • 解凍のみ:AR,ARJ,CAB,CHM,CPIO,CramFS,DMG,EXT,FAT,GPT,HFS,IHEX,ISO,LZH,LZMA,MBR,MSI,NSIS,NTFS,QCOW 2,RAR,RPM,SquashFS,UDF,UEFI,VDI,VHD,VMDK,WIM,XAR and Z.
  • 以下はコードを使用し、コメントに注意します.
    //   rx-main,       event  
    using System;
    using System.Configuration;
    using System.Diagnostics;
    using System.IO;
    using System.Reactive.Linq;
    
    namespace _7ZipTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                //var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "7ZipInstaller\\01.rar");
                //var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "7ZipInstaller\\02.7z");
                //var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "7ZipInstaller\\03.zip");
                var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "7ZipInstaller\\04.rar");
                try
                {
                    Console.WriteLine("     ...\r
    "); _7ZipHelper.UnZipFile(new FileInfo(filePath)); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.Read(); } } public class _7ZipHelper { /// /// 7Zip 【https://www.7-zip.org/】 7z /// private static string _7ZipExePath => ConfigurationManager.AppSettings[nameof(_7ZipExePath)]; private static string _7UnZipPath => ConfigurationManager.AppSettings[nameof(_7UnZipPath)]; /// /// 【x】 , /// c.7z E:\Program Files: /// 7z x c.7z -oE:\”Program Files” (-o , ) , /// E:\Program Files c , /// , E:\Program Files\c, c。 /// /// public static void UnZipFile(FileInfo fileInfo) { if (fileInfo.Exists) { Stopwatch watch = new Stopwatch(); watch.Start(); Process process = new Process(); process.EnableRaisingEvents = true; // process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.FileName = _7ZipExePath; process.StartInfo.Arguments = $@" x {fileInfo.FullName} -o{_7UnZipPath}\{Path.GetFileNameWithoutExtension(fileInfo.Name)}"; process.Start(); // process.BeginOutputReadLine(); // OutputDataReceived Observable.FromEventPattern(process, nameof(process.OutputDataReceived)) .Where(t => !string.IsNullOrEmpty(t.EventArgs.Data)) .Subscribe(e => { Console.WriteLine(e.EventArgs.Data); }); //7zip Observable.FromEventPattern(process, nameof(process.Exited)) .Subscribe(e => { watch.Stop(); Console.WriteLine($"\r
    ! :{watch.ElapsedMilliseconds} (ms)"); }); } else { Console.WriteLine($" :【{fileInfo.FullName}】"); } } } }

    転載先:https://www.cnblogs.com/xuxuzhaozhao/p/10341212.html