Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compress a directory with the built in .net compression classes?

Using the System.IO.Compression namespaces classes GZIPStream and DeflateStream I successfully can compress and decompress individual files. However, if I pass a directoryname as target for compression I get a security exception. Do I have to (recursively) enumerate all files and subdirectories to be able to compress a directory?

(Probably dotnetzip from codeplex will handle this better, but that is not what I am after now).

like image 750
Dabblernl Avatar asked Jan 29 '26 00:01

Dabblernl


1 Answers

When you use GZipStream etc, you are compressing a stream; not a file. GZip has no file header information, so there is no sensible way of packing multiple files. For that you need something like .zip; #ziplib will do the job, but you still (IIRC) need to feed it each file manually.

like image 132
Marc Gravell Avatar answered Feb 02 '26 01:02

Marc Gravell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!