網(wǎng)站首頁 編程語言 正文
壓縮文件:
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;
}
原文鏈接:https://www.cnblogs.com/wml-it/p/14729429.html
相關(guān)推薦
- 2022-08-15 LCP創(chuàng)建bond接口
- 2022-07-08 C語言完整實(shí)現(xiàn)12種排序算法(小結(jié))_C 語言
- 2022-12-12 Python生成直方圖方法實(shí)現(xiàn)詳解_python
- 2023-11-20 如何設(shè)置樹莓派4B的頻率?
- 2022-07-18 Linux 文件內(nèi)容瀏覽;cut命令;uniq命令;sort命令;tr命令;
- 2023-07-28 el-table 合并單元格(合并行)
- 2022-07-15 SQL?Server中的排名函數(shù)與分析函數(shù)詳解_MsSql
- 2022-09-21 android實(shí)現(xiàn)簡(jiǎn)單底部導(dǎo)航欄_Android
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支