Static void Main ()
{
String path = @ "D: \ Practise \ IO \ Compress ";
String deCompressPath = @ "D: \ Practise \ IO \ DeCompress ";
DirectoryInfo dir = new DirectoryInfo (path );
Foreach (FileInfo fi in dir. GetFiles ())
{
Compress (fi );
}
Foreach (FileInfo fi in dir. GetFiles ("*. cmp "))
{
DeCompress (fi, deCompressPath );
}
}
Public static void Compress (FileInfo fi)
{
Using (FileStream fs = fi. OpenRead ())
{
If (fi. Attributes! = FileAttributes. Hidden & fi. Extension! = ". Cmp ")
{
Using (FileStream compressfile = new FileStream (fi. FullName + ". cmp", FileMode. Create, FileAccess. ReadWrite ))
{
Using (DeflateStream ds = new DeflateStream (compressfile, CompressionMode. Compress ))
{
Fs. CopyTo (ds );
Console. WriteLine ("This File {0} has been Compressed to {1}", fi. Name, compressfile. Name );
}
} Www.2cto.com
}
}
}
Public static void DeCompress (FileInfo fi, string desination)
{
Using (FileStream fs = fi. OpenRead ())
{
String deCompressFile = fi. Name. Remove (fi. Name. Length-fi. Extension. Length );
Using (FileStream deCompressFS = new FileStream (Path. Combine (desination, deCompressFile), FileMode. Create, FileAccess. ReadWrite ))
{
Using (DeflateStream ds = new DeflateStream (fs, CompressionMode. Decompress ))
{
Ds. CopyTo (deCompressFS );
Console. WriteLine ("This file {0} has been Decompressd", fi. Name );
}
}
}
}
From the column ws_hgo