Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Aug 2001
    Location
    USA
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    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,

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    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.

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    [quote name='zymurgy' post='767652' date='26-Mar-2009 12:17']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?[/quote]
    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:\testing\Open_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.

  4. #4
    2 Star Lounger
    Join Date
    Aug 2001
    Location
    USA
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your code did the trick.

    Thanks.





    [quote name='jscher2000' post='767658' date='26-Mar-2009 15:36']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:\testing\Open_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. [/quote]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •