Windows XP and above has the built-in ability to create zip files. I found an example on the internet to tap in to this function. But it was in C# so I translated it to PowerBasic Windows 9.00 code.
Post comments or questions here: http://www.powerbasic.com/support/pb...ad.php?t=38472
Enjoy.
FYI, here is the link to the C# example
Post comments or questions here: http://www.powerbasic.com/support/pb...ad.php?t=38472
Enjoy.
Code:
'============================================================================== ' Example of how to create a zip file using windows built-in ZIP capibilities ' Created by William Burns using PB 9.00 on 09/03/2008 ' ' Note: Requires Windows XP or newer. ' '============================================================================== #COMPILER PBWIN 9 #COMPILE EXE #DIM ALL #INCLUDE "WinShell.inc" 'created by the PowerBasic Com browser on Shell32 lib 'adjust these constants to match your folder and zip file $SourceFolder = "C:\MyTestFolder" $DestinationZip = "c:\MyNewZip.ZIP" '============================================================================== FUNCTION PBMAIN local hFile as dword 'Object Variables DIM oShellClass AS IShellDispatch DIM oSourceFolder AS Folder DIM oTargetFolder AS Folder DIM oItems AS FolderItems 'variants DIM vSourceFolder AS VARIANT DIM vTargetFolder AS VARIANT DIM vOptions AS VARIANT 'First we create a empty ZIP file using a standard zip file header try hFile = freefile open $DestinationZip for output as #hFile print #hFile, 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 #hFile catch msgbox "Error creating Zip file.",,Error$(err) exit function end try ' Get an instance of our Windows Shell oShellClass = ANYCOM $PROGID_SHELL32_SHELL ' Did we get the object? If not, terminate this app IF ISFALSE ISOBJECT(oShellClass) OR ERR THEN MSGBOX "Could not get the Windows Shell object.",,"Error:" & str$(err) EXIT FUNCTION END IF 'assign the source folder we want to zip up vSourceFolder = $SourceFolder oSourceFolder = oShellClass.NameSpace(vSourceFolder) IF ISFALSE ISOBJECT(oSourceFolder) OR ERR THEN MSGBOX "Could not get the Source folder object.",,"Error:" & str$(err) goto Terminate END IF 'assign the target folder we want to create (in this case it is a zip file) vTargetFolder = $DestinationZip oTargetFolder = oShellClass.NameSpace(vTargetFolder) IF ISFALSE ISOBJECT(oTargetFolder) OR ERR THEN MSGBOX "Could not get the Target folder object.",,"Error:" & str$(err) goto Terminate END IF 'assign all the items in the source folder to the Items object oItems = oSourceFolder.Items() IF ISFALSE ISOBJECT(oItems) OR ERR THEN MSGBOX "Could not get the Items object.",,"Error:" & str$(err) goto Terminate END IF 'now we start the copy in to the new zip file vOptions = 20 oTargetFolder.CopyHere(oItems, vOptions) IF ERR THEN MSGBOX "Got an Error during the CopyHere method.",,"Error:" & str$(err) goto Terminate END IF 'NOTE: the above copyhere method starts a seperate thread to do the copy 'so the command could return before the copy is finished, so we need to 'allow time to complete. Thus the next Sleep command. sleep 2000 'increase for larger folders MSGBOX "All done! Now wasn't that easy?",,"Windows Zip" Terminate: ' Close all of the Interfaces oItems = NOTHING oTargetFolder = NOTHING oSourceFolder = NOTHING oShellClass = NOTHING END FUNCTION
Comment