C#通過(guò)cmd調(diào)用7z軟件實(shí)現(xiàn)壓縮和解壓文件
壓縮文件:
public object CompressZipFile(string sourceFile, string destinationFile)
{
object resObj;
Process process = new Process();
string tempDestinationFile = "";
try
{
if (process == null)
{
process = new Process();
}
tempDestinationFile = destinationFile.ToLower().EndsWith(".zip") ? destinationFile : destinationFile + ".zip";
process.StartInfo.FileName = "cmd.exe";
string command1 = @"cd c:\progra~1\7-zip";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
process.Start();
process.StandardInput.WriteLine(@"c:");
process.StandardInput.WriteLine(@"cd\");
process.StandardInput.WriteLine(command1);
process.StandardInput.WriteLine(@"7Z a -tzip " + destinationFile + " " + sourceFile);
process.StandardInput.WriteLine("exit");
string output = process.StandardOutput.ReadToEnd();
if (output.ToUpper().IndexOf("EVERYTHING IS OK") > -1)
{
resObj = new object[] { 0, "Compress file[" + destinationFile + "] OK" };
}
else
{
resObj = new object[] { 1, "Compress File[" + destinationFile + "] Error!" };
}
}
catch (Exception ex)
{
resObj = new object[] { 1, "Compress File[" + destinationFile + "] exception:" + ex.Message };
}
return resObj;
}解壓文件:
public object decompressFile(string zipFilepath, string FileDir)
{
object resObj;
try
{
string batfiledata = @"c:\progra~1\7-zip\7z.exe x " + zipFilepath + " -o" + FileDir + " -y";
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = "/c " + batfiledata;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
process.Start();
string output = process.StandardOutput.ReadToEnd();
if (output.ToUpper().IndexOf("EVERYTHING IS OK") > -1)
{
resObj = new object[] { 0, "解壓完成" };
}
else
{
resObj = new object[] { 1, "解壓出錯(cuò)!" };
}
}
catch (Exception ex)
{
resObj = new object[] { 1, ex.Message };
}
return resObj;
}到此這篇關(guān)于C#通過(guò)cmd調(diào)用7z軟件實(shí)現(xiàn)壓縮和解壓文件的文章就介紹到這了。希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- C#壓縮或解壓rar、zip文件方法實(shí)例
- C#調(diào)用7z實(shí)現(xiàn)文件的壓縮與解壓
- 詳解C#壓縮、解壓文件夾/文件(帶密碼)
- C#使用GZipStream實(shí)現(xiàn)文件的壓縮與解壓
- c# 文件壓縮zip或?qū)ip文件解壓的方法
- c#打包文件解壓縮的實(shí)例
- C#實(shí)現(xiàn)壓縮和解壓縮的方法示例【Gzip和Zip方式】
- C#實(shí)現(xiàn)文件壓縮與解壓的方法示例【ZIP格式】
- ASP.NET 文件壓縮解壓類(C#)
- C#使用WinRar命令進(jìn)行壓縮和解壓縮操作的實(shí)現(xiàn)方法
- C#中ZipHelper 壓縮和解壓幫助類
相關(guān)文章
C#實(shí)現(xiàn)定時(shí)任務(wù)Task Scheduler的示例代碼
這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)定時(shí)任務(wù)Task Scheduler的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-02-02
Asp.Net中避免重復(fù)提交和彈出提示框的實(shí)例代碼
本文分為前臺(tái)和后臺(tái)代碼實(shí)現(xiàn)避免重復(fù)提交和彈出提示框效果,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的的朋友參考下2017-02-02
C#實(shí)現(xiàn)String字符串轉(zhuǎn)化為SQL語(yǔ)句中的In后接的參數(shù)詳解
在本篇文章中小編給大家分享的是一篇關(guān)于C#實(shí)現(xiàn)String字符串轉(zhuǎn)化為SQL語(yǔ)句中的In后接的實(shí)例內(nèi)容和代碼,需要的朋友們參考下。2020-01-01
C#實(shí)現(xiàn)仿QQ抽屜式窗體的設(shè)計(jì)方法
QQ軟件對(duì)于絕大多數(shù)的人來(lái)說(shuō)再熟悉不過(guò)了,它以使用方便、界面美觀及功能完善而著稱,本文給大家介紹了C#實(shí)現(xiàn)仿QQ抽屜式窗體的設(shè)計(jì)方法,主要通過(guò)使用API函數(shù)WindowFromPoint和GetParent實(shí)現(xiàn)仿QQ的抽屜式窗體,需要的朋友可以參考下2024-04-04
C# 連接SQL數(shù)據(jù)庫(kù)的方法及常用連接字符串
這篇文章主要介紹了C# 連接SQL數(shù)據(jù)庫(kù)的方法及常用連接字符串,有需要的朋友可以參考一下2014-01-01
C# Csv實(shí)現(xiàn)基本的讀寫和轉(zhuǎn)換DataTable
本文主要介紹了C# Csv實(shí)現(xiàn)基本的讀寫和轉(zhuǎn)換DataTable,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02
C#使用OpenCvSharp實(shí)現(xiàn)透視變換功能
這篇文章主要為大家詳細(xì)介紹了C#如何使用OpenCvSharp實(shí)現(xiàn)透視變換的功能,文中的示例代碼簡(jiǎn)潔易懂,具有一定的學(xué)習(xí)價(jià)值,需要的小伙伴可以參考下2023-11-11

