Compress the underlying stream.
Imports System.IO
Imports System.IO.Compression
Module Module1
Sub Main()
Dim dirpath As String = "c:\"
Dim di As DirectoryInfo = New DirectoryInfo(dirpath)
For Each fi As FileInfo In di.GetFiles()
Compress(fi)
Next
End Sub
Private Sub Compress(ByVal fi As FileInfo)
Using inFile As FileStream = fi.OpenRead()
If (File.GetAttributes(fi.FullName) And FileAttributes.Hidden) _
<> FileAttributes.Hidden And fi.Extension <> ".gz" Then
Using outFile As FileStream = File.Create(fi.FullName + ".gz")
Using Compress As GZipStream = _
New GZipStream(outFile, CompressionMode.Compress)
inFile.CopyTo(Compress)
Console.WriteLine("Compressed {0} from {1} to {2} bytes.", _
fi.Name, fi.Length.ToString(), outFile.Length.ToString())
End Using
End Using
End If
End Using
End Sub
End Module
Related examples in the same category