• Counting Zip File Contents

    • This topic has 3 replies, 3 voices, and was last updated 16 years ago.
    Author
    Topic
    #458605

    Is there a way via VB/VBA to go through a folder containing numerous zip files, and return the number of files contained in each zip file?

    I would prefer not having to manually open each zip file.

    Thanks,

    Viewing 1 reply thread
    Author
    Replies
    • #1153719

      Although Windows XP and later have built-in support for zip files (aka compressed folders), VBA hasn’t kept up with it, so it doesn’t “know” how to handle zip files.

    • #1153720

      Is there a way via VB/VBA to go through a folder containing numerous zip files, and return the number of files contained in each zip file?

      I found some code samples, but they were not in VB so I’m not sure which library to add. Just using Object makes it it difficult to discover the relevant properties and methods.

      This code displays the count of the top level of the ZIP file. However, it does not traverse all of the folders in the archive, so that may understate the contents. (Or, since it displays the count for either a folder or a file, it might overstate the count. More work obviously is needed on this…)

      Code:
      Sub EnumerateZip()
      Dim sh As Object, fld As Object
      Set sh = CreateObject("Shell.Application")
      Set fld = sh.namespace("c:testingOpen_in_Fx.zip")
      MsgBox "Items: " & fld.items.Count
      'Stop 'View Locals window
      Set fld = Nothing
      Set sh = Nothing
      End Sub

      Oh, I think I found something that might help up on MSDN: Folder Object.

      Hopefully you can find some pre-baked code that handles this easily.

      • #1154440

        Your code did the trick.

        Thanks.

        I found some code samples, but they were not in VB so I’m not sure which library to add. Just using Object makes it it difficult to discover the relevant properties and methods.

        This code displays the count of the top level of the ZIP file. However, it does not traverse all of the folders in the archive, so that may understate the contents. (Or, since it displays the count for either a folder or a file, it might overstate the count. More work obviously is needed on this…)

        Code:
        Sub EnumerateZip()
        Dim sh As Object, fld As Object
        Set sh = CreateObject("Shell.Application")
        Set fld = sh.namespace("c:testingOpen_in_Fx.zip")
        MsgBox "Items: " & fld.items.Count
        'Stop 'View Locals window
        Set fld = Nothing
        Set sh = Nothing
        End Sub

        Oh, I think I found something that might help up on MSDN: Folder Object.

        Hopefully you can find some pre-baked code that handles this easily.

    Viewing 1 reply thread
    Reply To: Counting Zip File Contents

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: