最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#通過(guò)cmd調(diào)用7z軟件實(shí)現(xiàn)壓縮和解壓文件

 更新時(shí)間:2022年04月14日 14:39:44   作者:農(nóng)碼一生  
這篇文章介紹了C#通過(guò)cmd調(diào)用7z軟件實(shí)現(xiàn)壓縮和解壓文件的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

壓縮文件:

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í)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

镶黄旗| 保山市| 罗田县| 丹巴县| 桐乡市| 仪陇县| 如东县| 临桂县| 建德市| 和平县| 萍乡市| 高淳县| 九江县| 无棣县| 鄂温| 开封县| 卢氏县| 云林县| 蓝山县| 黔南| 桐庐县| 乌审旗| 嘉义县| 仁怀市| 阿图什市| 治县。| 英山县| 越西县| 繁昌县| 吉首市| 云林县| 富裕县| 山丹县| 岐山县| 泗水县| 吉安市| 遵义县| 大城县| 元朗区| 周至县| 杂多县|