This program uses the WinRAR program to compress the file. For command line syntax, see WinRAR help.
/// <Summary>
- /// Use WinRAR for compression
- /// </Summary>
- /// <Param name = "path"> folder to be compressed (absolute path) </param>
- /// <Param name = "rarpath"> compressed. rar directory (absolute path) </param>
- /// <Param name = "rarname"> name (including suffix) of the compressed file </param>
- /// <Returns> true or false. True is returned if compression is successful. Otherwise, false is returned. </Returns>
- PublicBool RAR (string path, string rarpath, string rarname)
- {
- Bool flag =False;
- String rarexe; // The complete path of winrar.exe
- Registrykey regkey; // registry key
- Object regvalue; // key value
- String cmd; // WinRAR Command Parameters
- Processstartinfo startinfo;
- Process process;
- Try
- {
- Regkey = registry. classesroot. opensubkey (@ "applications \ winrar.exe \ shell \ open \ command ");
- Regvalue = regkey. getvalue (""); // the key value is "D: \ Program Files \ WinRAR \ winrar.exe" "% 1"
- Rarexe = regvalue. tostring ();
- Regkey. Close ();
- Rarexe = rarexe. substring (1, rarexe. Length-7); // D: \ Program Files \ WinRAR \ winrar.exe
- Directory. createdirectory (PATH );
- // The compression command, which is equivalent to right-clicking on the folder (PATH) to be compressed-> WinRAR-> adding to the compressed file-> entering the compressed file name (rarname)
- Cmd = string. Format ("A {0} {1}-R", rarname, PATH );
- Startinfo =NewProcessstartinfo ();
- Startinfo. filename = rarexe;
- Startinfo. Arguments = cmd; // set Command Parameters
- Startinfo. windowstyle = processwindowstyle. Hidden; // hide the WinRAR window
- Startinfo. workingdirectory = rarpath;
- Process =NewProcess ();
- Process. startinfo = startinfo;
- Process. Start ();
- Process. waitforexit (); // wait for the winrar.exe process to exit indefinitely
- If(Process. hasexited)
- {
- Flag =True;
- }
- Process. Close ();
- }
- Catch(Exception E)
- {
- ThrowE;
- }
- ReturnFlag;
- }
- /// <Summary>
- /// Decompress the package using WinRAR
- /// </Summary>
- /// <Param name = "path"> extract the file path (absolute) </param>
- /// <Param name = "rarpath"> storage directory of the. rar file to be decompressed (absolute path) </param>
- /// <Param name = "rarname"> Name Of The. rar file to be decompressed (including the suffix) </param>
- /// <Returns> true or false. True is returned for successful decompression. Otherwise, false is returned. </Returns>
- PublicBool unrar (string path, string rarpath, string rarname)
- {
- Bool flag =False;
- String rarexe;
- Registrykey regkey;
- Object regvalue;
- String cmd;
- Processstartinfo startinfo;
- Process process;
- Try
- {
- Regkey = registry. classesroot. opensubkey (@ "applications \ winrar.exe \ shell \ open \ command ");
- Regvalue = regkey. getvalue ("");
- Rarexe = regvalue. tostring ();
- Regkey. Close ();
- Rarexe = rarexe. substring (1, rarexe. Length-7 );
- Directory. createdirectory (PATH );
- // Decompress the command, which is equivalent to right-clicking on the file to be compressed (rarname)-> WinRAR-> decompressing to the current folder
- Cmd = string. Format ("X {0} {1}-y", rarname, PATH );
- Startinfo =NewProcessstartinfo ();
- Startinfo. filename = rarexe;
- Startinfo. Arguments = cmd;
- Startinfo. windowstyle = processwindowstyle. hidden;
- Startinfo. workingdirectory = rarpath;
- Process =NewProcess ();
- Process. startinfo = startinfo;
- Process. Start ();
- Process. waitforexit ();
- If(Process. hasexited)
- {
- Flag =True;
- }
- Process. Close ();
- }
- Catch(Exception E)
- {
- ThrowE;
- }
- ReturnFlag;
- }
/// <Summary> /// use WinRAR for compression /// </Summary> /// <Param name = "path"> the folder to be compressed (absolute path) </param> /// <Param name = "rarpath"> compressed. RAR storage directory (absolute path) </param> // <Param name = "rarname"> name of the compressed file (including the suffix) </param> /// <returns> true or false. True is returned if compression is successful. Otherwise, false is returned. </Returns> Public bool RAR (string path, string rarpath, string rarname) {bool flag = false; string rarexe; // The complete path of winrar.exe is registrykey regkey; // registry key object regvalue; // key value string cmd; // The WinRAR command parameter processstartinfo startinfo; process; try {regkey = registry. classesroot. opensubkey (@ "applications \ winrar.exe \ shell \ open \ command"); regvalue = regkey. getvalue (""); // the key value is "D: \ Program Files \ WinRAR \ Winrar.exe "" % 1 "rarexe = regvalue. tostring (); regkey. close (); rarexe = rarexe. substring (1, rarexe. length-7); // D: \ Program Files \ WinRAR \ winrar.exe directory. createdirectory (PATH); // The compression command, which is equivalent to right-clicking on the folder (PATH) to be compressed-> WinRAR-> adding to the compressed file-> entering the compressed file name (rarname) cmd = string. format ("A {0} {1}-R", rarname, PATH); startinfo = new processstartinfo (); startinfo. filename = rarexe; startinfo. arguments = cmd; // set Command Parameters Startinfo. windowstyle = processwindowstyle. hidden; // hide the startinfo WinRAR window. workingdirectory = rarpath; process = new process (); process. startinfo = startinfo; process. start (); process. waitforexit (); // wait for the process winrar.exe to exit if (process. hasexited) {flag = true;} process. close () ;}catch (exception e) {Throw e ;}return flag ;} /// <summary> /// decompress the file using WinRAR /// </Summary> /// <Param name = "path"> Extract path (absolute) </param> // <Param name = "rarpath"> to decompress. RAR file storage directory (absolute path) </param> // <Param name = "rarname"> to be decompressed. RAR file name (including suffix) </param> // <returns> true or false. True is returned for successful decompression. Otherwise, false is returned. </Returns> Public bool unrar (string path, string rarpath, string rarname) {bool flag = false; string rarexe; registrykey regkey; object regvalue; string cmd; processstartinfo startinfo; process process; try {regkey = registry. classesroot. opensubkey (@ "applications \ winrar.exe \ shell \ open \ command"); regvalue = regkey. getvalue (""); rarexe = regvalue. tostring (); regkey. close (); rarexe = rarexe. substring (1, rarexe. length-7); directory. createdirectory (PATH); // decompress the command, which is equivalent to right-click the file to be compressed (rarname)-> WinRAR-> decompress it to the current folder cmd = string. format ("X {0} {1}-y", rarname, PATH); startinfo = new processstartinfo (); startinfo. filename = rarexe; startinfo. arguments = cmd; startinfo. windowstyle = processwindowstyle. hidden; startinfo. workingdirectory = rarpath; process = new process (); process. startinfo = startinfo; process. start (); process. waitforexit (); If (process. hasexited) {flag = true;} process. close () ;}catch (exception e) {Throw e ;}return flag ;}
Run the CD command in DOS or cmd to enter the WinRAR installation directory. Enter unrar and the following prompt is displayed:
Usage: unrar <command>-<switch 1>-<switch n> <compressed file> <file...>
<@ List file...> <decompress path \>
<Command>
E. decompress the compressed file to the current directory.
L [T, B] list compressed files [technical information, concise]
P print the file to the standard output device
T test compressed files
V [T, B] detailed list of compressed files [technical information, concise]
X decompress the file using the absolute path
<Switch>
-Stop Scanning
After the AC is compressed or unzipped, the archive attributes are cleared.
AD: Add compressed file names to the target path
AP <format> Add path to compressed file
AV-Disable User identity verification
C-Disable annotation display
CFG-Disable read Configuration
CL name to lowercase
Convert Cu name to uppercase
DH open shared files
EP exclusion path from name
The EP3 extension path is the full path containing the drive letter.
F. Refresh the file
Id [c, d, p, q] disable messages
Ierr sends all messages to standard error Devices
Inul disables all messages
After ioff completes an operation, turn off the PC power supply.
KB retains damaged decompressed files
N <File> only contains the specified file
N @ read the file name from the standard input device to include
N @ <list> include files in the specified file list
O + overwrite existing files
O-Do Not Overwrite existing files
Set NTFS compression attribute for OC
Or automatically rename the file
Ow save or restore the file owner and group
P [Password] Set Password
P-No Password inquiry
R recursive subdirectory
RI <p> [: <S>] sets the priority (0-default, 1-minimum... 15-maximum) and sleep time in milliseconds.
SL <size> process files smaller than the specified size
SM <size> processes files larger than the specified size
File Modified after ta <date> Add date <date>, in the format of yyyymmddhhmmss
File Modified before TB <date> Add date <date>, in the format of yyyymmddhhmmss
Files after tn <time> Add <time>
To <time> add files earlier than <time>
TS <m, C, A> [N] file retention or recovery time (modify, create, access)
U Update file
V. list all volumes
Ver [N] file version control
VP is paused before each volume
X <File> exclude specified files
X @ read the file name to be excluded from the standard input device
X @ <list> exclude objects in a specified list file
Y. If yes
Example of how to use WinRAR to decompress a file in DOS (CMD:
Suppose there is a winrar.rar in drive D. to decompress it to the hello folder in drive F, enter the following command under DOS:
Unrar x D: \ winrar.rar F: \ Hello \