1. Create a zip file and add the file:
| The code is as follows: |
Copy code |
Using (ZipFile zip = ZipFile. Create (@ "E: test.zip ")) { Zip. BeginUpdate (); Zip. Add (@ "E: file 1.txt "); Zip. Add (@ "E: file 2.txt "); Zip. CommitUpdate (); } |
2. Compress folders into files
| The code is as follows: |
Copy code |
(New FastZip (). CreateZip (@ "E: test.zip", @ "E: test", true ,"");
|
The last parameter is a filter file rule represented by a regular expression. The CreateZip method has three overloaded versions, including Directory filter parameters, File Filter parameters, and a bool type parameter used to specify whether sub-directory recursion is performed.
3. Add the file to an existing zip file.
| The code is as follows: |
Copy code |
Using (ZipFile zip = new ZipFile (@ "E: test.zip ")) { Zip. BeginUpdate (); Zip. Add (@ "E: test.doc "); Zip. CommitUpdate (); }
|
4. List zip files
| The code is as follows: |
Copy code |
Using (ZipFile zip = new ZipFile (@ "E: test.zip ")) { String list = string. Empty; Foreach (ZipEntry entry in zip) { List + = entry. Name + "rn "; } MessageBox. Show (list ); }
|
5. Delete a file in the zip file
| The code is as follows: |
Copy code |
Using (ZipFile zip = new ZipFile (@ "E: test.zip ")) { Zip. BeginUpdate (); Zip.Delete(@”test.doc "); Zip.Delete(@”test22.txt "); Zip. CommitUpdate (); }
|
6. Decompress the zip file to the specified directory.
| The code is as follows: |
Copy code |
(New FastZip (). ExtractZip (@ "E: test.zip", @ "E: test ",""); |