Encryption compression and decompression of files using WinRAR in C

  • 2021-07-09 09:03:18
  • OfStack

This example mainly implements:
1. Compress the folder and its files
2. Compress the files in the folder
3. Is the compressed folder and its files rar or zip
4. Decompress
5. Encryption compression and de-encryption compression
-----------
The sample code is as follows:


protected void Button1_Click(object sender, EventArgs e)
  {
    string strtxtPath = "C://freezip//free.txt";
    string strzipPath = "C://freezip//free.zip";
    System.Diagnostics.Process Process1 = new System.Diagnostics.Process();
    Process1.StartInfo.FileName = "Winrar.exe";
    Process1.StartInfo.CreateNoWindow = true;

    //// 1
    //// Compression c:/freezip/free.txt( That is, folders and files under them freezip/free.txt)
    //// To c:/freezip/free.rar
    //strzipPath = "C://freezip//free";// The default compression method is  .rar
    //Process1.StartInfo.Arguments = " a -r " + strzipPath + " " + strtxtPath;

    //// 2
    //// Compression c:/freezip/free.txt( That is, folders and files under them freezip/free.txt)
    //// To c:/freezip/free.rar
    //strzipPath = "C://freezip//free";// Set the compression mode to  .zip
    //Process1.StartInfo.Arguments = " a -afzip " + strzipPath + " " + strtxtPath;

    //// 3
    //// Compression c:/freezip/free.txt( That is, folders and files under them freezip/free.txt)
    //// To c:/freezip/free.zip  Directly set to free.zip
    //Process1.StartInfo.Arguments = " a -r "+strzipPath+" " + strtxtPath ;

    //// 4
    //// Relocation compression c:/freezip/free.txt( That is, folders and files under them freezip/free.txt)
    //// To c:/freezip/free.rar  After compression   The original file will not exist 
    //Process1.StartInfo.Arguments = " m " + strzipPath + " " + strtxtPath;

    //// 5
    //// Compression c:/freezip/ Under free.txt( I.e. documents free.txt)
    //// To c:/freezip/free.zip  Directly set to free.zip  Files only   Without a folder 
    //Process1.StartInfo.Arguments = " a -ep " + strzipPath + " " + strtxtPath;

    //// 6
    //// Decompression c:/freezip/free.rar
    //// To  c:/freezip/
    //strtxtPath = "c://freezip//";
    //Process1.StartInfo.Arguments = " x " + strzipPath + " " + strtxtPath;

    //// 7
    //// Encryption compression c:/freezip/free.txt( That is, folders and files under them freezip/free.txt)
    //// To c:/freezip/free.zip  Password is 123456  Be careful not to have spaces between parameters 
    //Process1.StartInfo.Arguments = " a -p123456 " + strzipPath + " " + strtxtPath;

    //// 8
    //// Decompressed encrypted c:/freezip/free.rar
    //// To  c:/freezip/   Password is 123456  Be careful not to have spaces between parameters 
    //strtxtPath = "c://freezip//";
    //Process1.StartInfo.Arguments = " x -p123456 " + strzipPath + " " + strtxtPath;

    Process1.Start();  
    if (Process1.HasExited)
    {
      Response.Write(" Finish ");
    }
  }

# re: C # (Encryption) Compress and decompress related folders and files

More WinRAR commands (quoted from WinRAR help documentation)
a Add File to Zip File
c Add Compressed File Comments
d Delete files from compressed files
e Extract compression from compressed file, ignoring path
f Refresh Files in Compressed Files
i Finding Strings in Compressed Files
k locking compressed files
m Move files and folders to zip files
r Repairs Corrupted Compressed Files
rc Reconstruct Lost Volume
rn Rename Compressed File
rr [N] Add Data Recovery Record
rv [N] Create Recovery Volume
s [name] Converts compressed files to self-extracting file types
s-Delete self-extracting module
t test zip file
u Update files from compressed files
x Extract compressed file with full path name compressed reply more comments

# re: C # (Encryption) Compresses and decompresses related folders and files

More WinRAR Begins (quoted from WinRAR Help Documentation)
-ac Clear archive properties after compression or decompression
-ad append the compressed file name to the destination path
-af < Type > Specify the compressed file format
-ag [Format] generates compressed file name with current date
-ao Adds an archive property setting
-ap Set internal compressed file path
-as Synchronize the contents of compressed files
-av Application User Identity Verification Information
-av-Disable adding user authentication information
-cfg-Ignore default configuration and environment variables
-cl converts file names to lowercase
-cu converts file names to uppercase
-df delete compressed files after compression
-dh Open a shared file
-ds does not sort compressed files
-ed Do not add empty folders
-en does not add "end of compressed file" block
-ep Exclude paths from names
-ep1 Exclude Home Folder from Name
-ep2 expanded into a complete path
-ep3 extension contains the full path of the drive letter
-e[+] < Attribute > Setting file exclusion and inclusion properties
-f refresh file
-hp [password] encrypts file data and headers
-ibck Run WinRAR in the background
-ieml Send compressed files using E-mail
-iicon < Name > Specify a self-extracting icon
-iimg < Name > Specify a self-extracting picture
-ilog [name] logs error to file
-inul shutdown error message
-ioff Power off PC
-k lock compressed file
-kb Keep broken unzipped files
-m < n > Set the compression mode
-mc < Parameter > Setting Advanced Compression Parameters
-md < n > Select dictionary size
-ms Specifies file storage
-n < Documents > Include only the specified files
-n@ < List file > Includes a file using the specified list file
-os Saves NTFS Data Stream
-oc Set the NTFS "Compression" property
-ow handles file user authentication information
-o + Overwrite existing files
-o-Do not overwrite existing files
-p [password] Set password
-r Return to Subfolder
-r0 returns only subfolders that match wildcard characters
-ri Setting Priority and Hibernation Time
-rr [N] Add data recovery records
-rv [N] Create Recovery Volume
-s Creating solid compressed files
-s < N > Create a solid group by number of files
-se Create solid groups with file extensions
-sfx [name] Create a self-extracting file
-sv Creating solid compressed files that are independent of each other
-sv-Creating solid compressed files that depend on each other
-s-Disable solid algorithm
-t compressed test file
-ta < Date > Only files modified after the specified date are processed
-tb < Date > Only files modified before the specified date are processed
-tk Keep the original compressed file time
-tl Set the compressed file time with the latest file
-tn < Time > Processing files newer than the specified time
-to < Time > Processing files older than the specified time
-ts < m,c,a > Save or restore file time (modify, create, access)
-u update file
-v < n > [kbfmMgG] Create Volume Compression
-vd Clear disk contents before creating volume compression
-ver file version control
-vn uses old style volume naming rules
-vp pause before compressing each volume
-x < Documents > Exclude the specified file
-x@ < List of files > Excludes the specified file using the specified list file
-y assumes that all queries are answered "yes"
-z < Documents > Read compressed file comments from files
--Stop the scan of the switch


Related articles: