c# 使用7zip

1. 7zip 使用密码来压缩
C:\"Program Files"\7-Zip\7z.exe a -t7z D:\path\to\your\zip\files.zip

D:\path\to\your\1.csv -pSECRET

2. 使用密码来解压 (提取到当前目录)
C:\"Program Files"\7-Zip\7z.exe e -t7z D:\path\to\your\zip\files.zip -pSECRET

C# 调用

...
string arguments = $"e -t7z {_zipFilePath} -o{targetPath} -p{_password}";
                var process = new Process
                {
                    StartInfo =
                    {
                        Arguments = arguments,
                        FileName = _7zipPath,
                        WindowStyle = ProcessWindowStyle.Hidden
                    }
                };

                process.Exited += (sender, eventArgs) => { _log.Info("7zip process exited"); };
                process.ErrorDataReceived += (sender, eventArgs) => { _log.Info("7zip process got error"); };

                process.Start();
                _log.Info($"7zip process started. 7zip path :{_7zipPath} arguments :{arguments}");

                process.WaitForExit();
                _log.Info("7zip process done");
...

 

你可能感兴趣的:(c#,编程)