Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting access to Zip a file 1

Status
Not open for further replies.

Genie78

MIS
Aug 11, 2008
18
GB
Hi there i have need for access to zip a file using winzip or winrar depending on what is on the pc that is using the DB.

is there some simple vb code that can do this?

Ta
 
Too easy mate, we use a function and a class in conjunction with zip32.dll. Works VERY well for a large commercial application. The code is too long to post here but try searching for this:

' Accesss WinZip
' (c) - Albert D. Kallal - July 2006
'
' You are free to use this code, and even use this code
' in your commerial applications.

That's the copyright at the top of the main function.

If you have any drama come back to me and we'll arrange some way of posting the full function here for everyone to use.

Take it easy, JB

 
If the question is:"How to zip or unzip an object using a VB code" first of all you need to have installed the two utilities free downloadable from the Winzip website called wzzip.exe and wzunzip.exe.

On the website you will find and example of VB code or VBScript code.

The all is under the charpet Add On in the Winzip site.

Here I report you an example of code just to add File1.txt and File2.doc on File.zip .
Call Shell("C:\Programms\WinZip\wzzip.exe C:\Folder1\Folder2\File.zip C:\FolderA\FolderB\File1.txt C:\FolderC\FolderD\File2.doc", vbMaximizedFocus)

Let me know!



 
If the question is:"How to zip or unzip an object using a VB code" first of all you need to have installed the two utilities free downloadable from the Winzip website called wzzip.exe and wzunzip.exe.

On the website you will find and example of VB code or VBScript code.

The all is under the charpet Add On in the Winzip site.

Here I report you an example of code just to add File1.txt and File2.doc on File.zip .
Code:
Call Shell("C:\Programms\WinZip\wzzip.exe C:\Folder1\Folder2\File.zip C:\FolderA\FolderB\File1.txt C:\FolderC\FolderD\File2.doc", vbMaximizedFocus)
Let me know!



 
Genie78

Should you choose to use sigmabeta's techniques, you should be aware that WinZip is not free software, you need to purchase a license for it beyond the initial trial period.

Sigmabeta,
Please make this clear to anybody you are recommending using WinZip or the WinZip command line addon tools.

John
 
The Microsoft Shell Controls and Automation reference can create and read ZIP files without messing with WinZip Addins.
Code:
Private Sub cmdZipIt_Click()
    Me.MousePointer = vbHourglass
    CreateEmptyZip "c:\myDir\testzip.zip"

    With CreateObject("Shell.Application")

        ' Copy a file into the compressed folder.
        .NameSpace("c:\myDir\testzip.zip").CopyHere _
                "c:\myDir\myMdb.mdb"

        'use this line if we want to zip all items in a folder into our zip file
        '.NameSpace("c:\myDir\testzip.zip").CopyHere .NameSpace("C:\myDir\Files").Items

    End With
    Me.MousePointer = vbDefault
End Sub

Public Sub CreateEmptyZip(sPath)
    Dim strZIPHeader                As String
    
    ' header required to convince Windows shell that this is really a zip file
    strZIPHeader = Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
    
    With CreateObject("Scripting.FileSystemObject")
        .CreateTextFile(sPath).Write strZIPHeader
    End With

End Sub

and to open a ZIP file
Code:
Private Sub ReadZip_Click()
    ShowZipFileContents "C:\myDir", "TestZip.zip"
End Sub

Public Sub ShowZipFileContents(FolderPath As String, Filename As String)
    Dim shApp                       As Shell32.Shell
    Dim shFolder                    As Shell32.Folder
    Dim shFolder2                   As Shell32.Folder
    Dim shFolderItem                As Shell32.FolderItem
    Dim shFolderItem2               As Shell32.FolderItem

    Set shApp = New Shell32.Shell
    Set shFolder = shApp.NameSpace(FolderPath)
    Set shFolderItem = shFolder.ParseName(Filename)
    Set shFolder2 = shFolderItem.GetFolder

    For Each shFolderItem2 In shFolder2.Items
        Debug.Print shFolderItem2.Name
    Next shFolderItem2
End Sub

This code courtesy of Strongm in the VB5&6 forum.
 
what would the code be for then extracting this file via a Bat file? without hopefully using win zip...
 
Genie,

Bat is an extension for "batch" file. It is a way of stringing together a bunch of commands into, well, a batch!

Unfortunately it these commands are dos type commands, for example,

net use z: //server/share
copy c:\myfile.txt z:\yourfile.txt
pause
etc

As I understand it winzip does have command line parameters you could use in a batch file but unless your user has the software they will be unable to run your bat file.

An aternative could be to knock up an applet that uses the code above to browse for the file and extract the contents?

JB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top