--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
Announcement
Collapse
No announcement yet.
Calling Windows Zip Function
Collapse
X
-
Originally posted by Thomas Tierney View PostThe 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?
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)
PS: thumbs down ????? Not sure where that came from. Just know that you don't want to get that from a Roman Emporer.
Leave a comment:
-
btw, what is a thumbs down?
Leave a comment:
-
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?
Leave a comment:
-
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?
Leave a comment:
-
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"
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?
Leave a comment:
-
Thomas,
Thanks for sharing. I think this is what I was looking for.
Leave a comment:
-
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
Leave a comment:
-
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.
Leave a comment:
-
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.
Leave a comment:
-
Leave a comment:
-
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?Tags: None
Leave a comment: