Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleZip all of the subdirectories within a directory
Description
KeywordsZip, WinZip, compress, directory, subdirectory
CategoriesUtilities, Files & Directories
 
Use Dir$ to loop through the subdirectories within the directory. Use the Shell statement to launch the WinZip command line interface to zip the subdirectories.
 
' Zip the subdirectories in this directory.
Private Sub cmdZip_Click()
Const ZIP_EXE As String = """C:\Program " & _
    "Files\WinZip\wzzip"""

Dim dir_name As String
Dim file_name As String
Dim full_path As String

    dir_name = txtDirectory.Text
    If Right$(dir_name, 1) <> "\" Then dir_name = dir_name _
        & "\"
    file_name = Dir$(dir_name, vbDirectory)
    Do While Len(file_name) > 0
        If file_name <> "." And file_name <> ".." Then
            ' Zip this directory.
            full_path = dir_name & file_name
            If GetAttr(full_path) And vbDirectory Then
                If Shell(ZIP_EXE & " -r -p " & _
                    full_path & ".zip " & full_path, _
                        vbHide) = 0 _
                Then
                    MsgBox "Zip Failed for " & file_name
                End If
            End If
        End If

        ' Get the next directory.
        file_name = Dir$(, vbDirectory)
    Loop

    MsgBox "Done"
End Sub
 
Apparently you can only shell WinZip in vbHide mode if you have licensed WinZip. If you are using the evaluation version, you need to run the shell in vbNormalFocus mode. Then WinZip displays a message saying it is running in evaluation mode and you must press a key to continue.

Thanks to Pooya Kashefifar for pointing this out!

WinZip is such a worthwhile program that I encourage you to register.

 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated