Announcement

Collapse
No announcement yet.

Calling Windows Zip Function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calling Windows Zip Function

    Windows Explorer (XP and later) have the ability to create a new ZIP file.

    Is there a way (programmatically) to call Windows Explorer's function to create a new empty ZIP file and then copy files into files into that new ZIP file?

  • #2
    Martin,
    Wouldn't zlib do ?

    http://www.powerbasic.com/support/pb...highlight=zlib

    Kind regards
    Eddy

    Comment


    • #3
      Yeah, but why reinvent the wheel. I too would be interested in this, but doubt M$ has it well documented. I'd like to use the much Simpler TalkAny DLL files too instead of the Speech API, but that isn't possible yet either. And, I have the DLL and install method for those Zip Folders too and have got them to work on Win2K and before, so they are pretty universal.
      sigpic
      Mobile Solutions
      Sys Analyst and Development

      Comment


      • #4
        Only documented information I could find sometime ago, is how to script a zip folder and such.

        You could generate a script file via your program and run that script to do the zip work.
        A dozen what.

        Comment


        • #5
          If you feel like it...

          MS zip undocumented function

          Comment


          • #6
            There shouldnt be any special functions to call to use the zip functionality in XP/2003/HIGHER. Remember, the zip file is now tied to explorer and shell32. Here is a routine that should get you on your way. I suggest reading up on CopyHere if you need more indepth functionality
            Code:
            Function PBMain
                '-----------------------------------------------------------------------
                'Author :   Thomas Tierney
                'Purpose:   Using Shell32 to add files to a zip file
                'Date   :   12/18/2007
                '-----------------------------------------------------------------------
                Dim oShell As Dispatch
                Dim oDest As Dispatch
                Dim oSrc As Dispatch
                Dim oSrcItems As Dispatch
                Dim vDest1 As Variant
                Dim vDest2 As Variant
                Dim vSrc1 As Variant
                Dim vSrc2 As Variant
                Dim vItems As Variant
                Dim vFlags As Variant
                Dim sZipFile As String
                Dim sSourceFolder As String
            
            
                sZipFile = "c:\somefile.zip"
                sSourceFolder = "c:\SomeFolder"
            
                'create an empty zip file
                Open sZipFile For Output As #1
                Print #1, Chr$(80,75,5,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
                Close #1
            
                'Create the Shell object
                Set oShell = New Dispatch In ("Shell.Application")
                If IsObject(oShell) = 0 Then
                  MsgBox "Shell ERROR"
                  Exit Function
                End If
            
                vDest1 = sZipFile
                Object Call oShell.NameSpace(vDest1) To vDest2
                Let oDest = vDest2
                If IsObject(oDest) = 0 Then
                  MsgBox "DEST ERROR"
                  Set oShell = Nothing
                  Exit Function
                End If
            
                vSrc1 = sSourceFolder
                Object Call oShell.Namespace(vSrc1) To vSrc2
                Let oSrc = vSrc2
                If IsObject(oSrc) = 0 Then
                  Set oDest = Nothing
                  Set oShell = Nothing
                  MsgBox "SRC ERROR"
                  Exit Function
                End If
                Object Call oSrc.Items() To vItems
                Object Call oDest.CopyHere(vItems)
            
                MsgBox "You will need to wait here for the dialog to go away as the function doesnt report it."
            
            End Function
            Sr. Software Development Engineer and Sr. Information Security Analyst,
            CEH, Digital Forensic Examiner

            Comment


            • #7
              Thomas,
              Thanks for sharing. I think this is what I was looking for.

              Comment


              • #8
                Thomas,
                I have run into a little difficulty: I get an error message:

                The Specified directory C:\temp\ansi is empty.....

                However, I didnot set the directory to \ansi what I set was:

                Code:
                     sZipFile = "c:\temp\somefile.zip"
                     sSourceFolder = "c:\temp"
                I cannot see where in the code the source directory is getting changed.

                Could you explane how the files to be copied to the created ZIP file get selected. Let's say I wanted to copy C:\temp\*.bas to the created zip file, how would I do that?

                Comment


                • #9
                  Thomas,
                  Ok, I think I see how works... Appearently this routine tries to zip up everything including subfolders. If a subfolder is empty and error message is generated.
                  If I wanted to specify just certain files in a certain direcorty to be ZIPPed how would I do that?

                  Comment


                  • #10
                    The source object can be a file or a folder. If you use a path & filename in
                    vSrc = "c:\test.txt"
                    Object Call oShell.Namespace(vSrc1) To vSrc2

                    so you would need to do something like dir

                    sDir = Dir("c:\*.*")

                    while sDir <> ""
                    'add files here..
                    wend

                    I am not sure that is correct but you can look up the shell32 functions on MSDN, they are still there..

                    btw, what is a thumbs down?
                    Last edited by Thomas Tierney; 22 Dec 2007, 01:30 AM. Reason: saw something
                    Sr. Software Development Engineer and Sr. Information Security Analyst,
                    CEH, Digital Forensic Examiner

                    Comment


                    • #11
                      btw, what is a thumbs down?
                      1st thought that came to mind was that commercial that says "Delegate.......DOWN"
                      Engineer's Motto: If it aint broke take it apart and fix it

                      "If at 1st you don't succeed... call it version 1.0"

                      "Half of Programming is coding"....."The other 90% is DEBUGGING"

                      "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                      Comment


                      • #12
                        Originally posted by Thomas Tierney View Post
                        The source object can be a file or a folder. If you use a path & filename in
                        vSrc = "c:\test.txt"
                        Object Call oShell.Namespace(vSrc1) To vSrc2

                        so you would need to do something like dir

                        sDir = Dir("c:\*.*")

                        while sDir <> ""
                        'add files here..
                        wend

                        I am not sure that is correct but you can look up the shell32 functions on MSDN, they are still there..

                        btw, what is a thumbs down?
                        Thomas, Thanks for the explanation. I have not used the OBJECT functions of PowerBasic before, so this is unfamiliar code for me. I been reading the PB8 manual to try an get a better understanding. The code looks like it should be simple to understand but guess I'm a little slow... I don't quite understand exactly what's going on, particulary these two sections:

                        Code:
                            vDest1 = sZipFile
                            Object Call oShell.NameSpace(vDest1) To vDest2
                            Let oDest = vDest2
                            If IsObject(oDest) = 0 Then
                              MsgBox "DEST ERROR"
                              Set oShell = Nothing
                              Exit Function
                            End If
                        
                            vSrc1 = sSourceFolder
                            Object Call oShell.Namespace(vSrc1) To vSrc2
                            Let oSrc = vSrc2
                            If IsObject(oSrc) = 0 Then
                              Set oDest = Nothing
                              Set oShell = Nothing
                              MsgBox "SRC ERROR"
                              Exit Function
                            End If
                            Object Call oSrc.Items() To vItems
                            Object Call oDest.CopyHere(vItems)
                        I don't understand these Object calls. I know that an Object Call is simular to a PB SUB or FUNCTION call. I will study it some more. Thanks for the help.

                        PS: thumbs down ????? Not sure where that came from. Just know that you don't want to get that from a Roman Emporer.

                        Comment


                        • #13
                          --this assigns the string value to the variant
                          vDest1 = sZipFile

                          --this calls the method Namespace on the object oShell with the variant value and assigns its return the value to the variant vDest2
                          Object Call oShell.NameSpace(vDest1) To vDest2

                          -- this coerces the return variant into a dispatch object
                          Let oDest = vDest2

                          'this checks to see that an object is what exists
                          If IsObject(oDest) = 0 Then
                          MsgBox "DEST ERROR"

                          'this nullifies the original dispatch object and causes any code in its terminate routine run, cleaning up after itself
                          Set oShell = Nothing

                          Exit Function
                          End If
                          Sr. Software Development Engineer and Sr. Information Security Analyst,
                          CEH, Digital Forensic Examiner

                          Comment

                          Working...
                          X