command-line invocation winrar zip-Compress the folder sample code

Source: Internet
Author: User

Calling C # 's own API for compression

                Zip
                Destfullpath = destfullpath + "\" + _myconfig.zipfilename;
                if (file.exists (Destfullpath))
                    file.delete (destfullpath);
                Zipfile.createfromdirectory (_myconfig.tempfilefolder, Destfullpath);


Call WinRAR for compression

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;

Using System.Threading.Tasks; Namespace Testzipexe {class Program {static void Main (string[] args) {string Exepat
            h = "C:\\Program Files (x86) \\WinRAR\\winrar.exe";
             * * A To add a document, must have, otherwise will not output compressed files. *-K Lock Compressed files *-R including subdirectories *-M1 use the fastest way (low compression) *-EP1 exclude the base folder, or the compressed package will contain the folder to be compressed
             Full path *-o+ Overwrite existing file *-afzip specify compressed format as Zip * destination file (full path) * source folder * */String parameters = String.Format ("A-k-m1-ep1-afzip-r-o+ d:\\workspace\\cat8637_brand_2 0150211\\trunk\\cat8637_brand\\dest\\brand.zip d:\\workspace\\cat8637_brand_20150211\\trunk\\cat8637_brand\\

            Temp\\brand ");

            EXEC (exepath, parameters);
        Console.WriteLine ("End"); static public void exec (string exepath, string parameters) {System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStar
            Tinfo (); Psi.
            Redirectstandardoutput = true; Psi.
            Redirectstandarderror = true; Psi.
            WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; Psi.
            UseShellExecute = false; Psi.
            FileName = ExePath; Psi.
            Arguments = parameters;
            System.Diagnostics.Process Process = System.Diagnostics.Process.Start (PSI); System.IO.StreamReader Outputstreamreader = process.
            StandardOutput; System.IO.StreamReader Errstreamreader = process.

            StandardError;
            int i = 0; do {process.
                WaitForExit (2000);
            i++; while (process.


            HasExited = = False && i < 15); if (process.
            hasexited)//{//String output = Outputstreamreader.readtoend (); String ERror = Errstreamreader.readtoend ();
            MessageBox.Show (output);
            MessageBox.Show (Error);
 //}
        }
    }
}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.