Get A File's Information With System.IO.Compression RRS feed

  • Question

  • Is there a way to get a file's information like System.IO.FileInfo using System.IO.Compression to get each file's information in a compressed archive?  I would appreciate the help.
    Thursday, April 30, 2020 7:53 PM

All replies

  • Hello,

    This is what's available


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    Thursday, April 30, 2020 8:18 PM
  • Hi,

    You can try my code:

    Imports System.IO
    Imports System.IO.Compression
    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim zipPath As String = "MyTest.zip"
            Using archive = ZipFile.Open(zipPath, ZipArchiveMode.Read)
                For Each item As ZipArchiveEntry In archive.Entries
                    If item.Name <> "" Then
                        Using reader As New BinaryReader(item.Open())
                            System.IO.File.WriteAllBytes("D:\" & item.Name, ReadAllBytes(reader))
                        End Using
                    End If
            End Using
        End Sub
        Public Shared Function ReadAllBytes(reader As BinaryReader) As Byte()
            Const bufferSize As Integer = 4096
            Using ms As New MemoryStream()
                Dim buffer(bufferSize) As Byte
                Dim count As Integer
                    count = reader.Read(buffer, 0, buffer.Length)
                    If count > 0 Then ms.Write(buffer, 0, count)
                Loop While count <> 0
                Return ms.ToArray()
            End Using
        End Function
    End Class

    Best Regards,


    • Edited by Alex-KSGZ Friday, May 1, 2020 7:10 AM
    Friday, May 1, 2020 6:17 AM