Compression part:
Try
{
String rarexe = @ "C: \ Program Files \ WinRAR \ winrar.exe ";
// Complete winrar.exe path
String mulu = @ "F: \ store data \";
// Directory of the sub-File
String filelist = NULL;
Filelist + = (mulu + "newdb.xlsx ");
Filelist + = (mulu + "outbound database table .xlsx ");
Filelist + = (mulu + "a11-account .xlsx ");
Filelist + = (mulu + "a10-account .xlsx ");
Filelist + = (mulu + "a08-ledger .xlsx ");
Filelist + = (mulu + "a05-account .xlsx ");
// Organize the compressed file list
String cmd = string. Format ("A" + datetime. Now. tostring () + "{0}-r-ibck-inul", filelist );
// WinRAR Command Parameters
Processstartinfo startinfo = new processstartinfo ();
Startinfo. filename = rarexe;
// Set the compression master program location
Startinfo. Arguments = cmd;
// Set Command Parameters
Startinfo. workingdirectory = @ "F: \ store data \ backup \ 7 \";
// File storage path
Process = new process ();
// Create a new process
Process. startinfo = startinfo;
// Pass all parameters to the Process
Process. Start ();
// Start the process
Process. waitforexit ();
// Wait for the process winrar.exe to exit indefinitely
Process. Close ();
// Release all occupied Resources
MessageBox. Show ("compression completed! ");
}
Catch (exception E)
{
MessageBox. Show (E. Message );
}
Extract:
Try
{
String rarexe = @ "C: \ Program Files \ WinRAR \ winrar.exe ";
// Complete winrar.exe path
String jypath = @ "C :\";
// Decompress the storage path
Directory. createdirectory (jypath );
// Create a folder in the specified path
String cmd = string. Format ("X {0} {1}-ibck-inul", @ "F: \ store data \ 2014-7-10.rar", jypath );
// WinRAR Command Parameters
Processstartinfo startinfo = new processstartinfo ();
Startinfo. filename = rarexe;
// Set the compression master program location
Startinfo. Arguments = cmd;
// Set Command Parameters
Process = new process ();
// Create a new process
Process. startinfo = startinfo;
// Pass all parameters to the Process
Process. Start ();
// Start the process
Process. waitforexit ();
// Wait for the process winrar.exe to exit indefinitely
Process. Close ();
// Release all occupied Resources
MessageBox. Show ("decompressed to:" + jypath );
}
Catch (exception em)
{
MessageBox. Show (Em. Message );
}
Other parameters:
* <Command>-<switch 1>-<switch n> <compressed file> <file...> <@ list file...> <decompress path \> * compress a-as-ed-inul-afrar-DF-ibck-M4-mt3-or-y-hp123 D: \ aa d: \ aa.txt * decompress X-hp123-ibck-inul-y-mt5 D: \ aa.rar A: \ * a d: \ info.zip D: \ easyui *-AF: the specified format-afzip-afrar *-as does not exist in the list of currently added files, the files will be deleted from the compressed files *-DF compression and then the source files *-Dr will be deleted to the recycle bin *-ed will not add an empty folder *-HP add password-hp123456 *-ibck background run * -inul forbidden error message *-Turn off power after Loff compression *-M0 storage add files to compressed files but not compressed *-M1 most Fast and fast method (minimum compression ratio) *-m2 fast and Fast Compression Method *-m3 standard (default) compression Method *-M4 better compression method (higher compression ratio) *-M5 optimal compression method (highest compression ratio but slowest speed) *-MTN thread-mt5 1 ~ 32 *-or automatically rename the file *-r together with the sub-file *-Z after compression test file *-y all pop-up windows select "yes"
Copy winrar.exe directly to the root directory.
C # File compression and decompression