******************************************************* * * * A free zip file handler for XP * * * * Alan Shepard Mar 2004 * * * * Objective :- * * Use built in XP facilities to handle zip files. * * * * Most of the documented verbs work, but some * * are rather iffy . * * * * To do :- * * Find a way to extract a file from the zip. * * Confirm that delay option stabilises oFld. * * * ******************************************************* * Create an object to handle the zip file oZHandler = CREATEOBJECT('ZipHandler') * Try it out WITH oZHandler * Zip contents methods (start with 'f'). * Zip file methods (start with 'z'). * Step over each line below to see the result. .Doit('zNew','C:\temp\bookdata.zip') && Create a new zip file. .cZipName = 'C:\temp\bookdata.zip' && Set the handler to point to the zip file. .nDelay = 300 && Set the delay in milliseconds. lnFiles = ADIR(laFiles, 'data\*.*') && Create array FOR lnCount = 1 TO lnFiles && Loop for number of files lcFile=lower(fullpath('data\'+laFiles(lnCount,1))) ? lcfile,file(lcFile) .Doit('fAdd',lcFile) && Place file in the zip file =Sleep(.nDelay) ENDFOR *!* .Doit('fAdd','c:\list.xls') && Place file in the zip file *!* .Doit('fAdd','c:\develop\kevin\saturn\data\symast.dbf') && Place file in the zip file *!* .Doit('fAdd','c:\develop\kevin\saturn\data\clmast.dbf') && Place file in the zip file *!* lcFile='c:\develop\kevin\saturn\data\clmast.cdx' *!* .Doit('fAdd',lcFile) && Place file in the zip file * Troublesome methods * .Doit('zProperties') && Zip file properties. Sometimes works. * .Doit('zExtractTo') && Extract To. Fails for me. Try it. * .Doit('zShort') && Create shortcut. I get 'File copy error' sometimes. * .Doit('zRename') && Fails with OLE error. * .Doit('zShort') && Creates a shortcut. Sometimes fails. * .Doit('zCut') && Cut. Seems to do nothing. * Methods that work * .Doit('fOpen','fred.txt') && View contents of a text file. .Doit('zOpen') && View contents of the zip file. * .Doit('fCopy','fred.txt') && Copy. Copies to clipboard. * .Doit('fCut','fred.txt') && Cut. Seems to do nothing. * .Doit('fProperties','joe.txt') && Properties of joe.txt. * .Doit('fDelete','joe.txt') && Delete. * .Doit('zExplore') && Explore contents of the zip file. * .Doit('zSearch') && Search contents of a zip file. * .Doit('zExtractAll') && Extract contents of the zip file. * .Doit('zScan') && Anti Virus scan. * .Doit('zCopy') && Copy. Copies to clipboard. ENDWITH clear all DEFINE CLASS ZipHandler AS Custom cZipName = '' nDelay = 200 oShell = '' oFld = '' oIts = '' PROCEDURE Init This.oShell = CREATEOBJECT("Shell.Application") DECLARE INTEGER Sleep IN kernel32 AS Sleep ; INTEGER dwMilliseconds ENDPROC PROCEDURE Doit LPARAMETERS Action,FileName Action = LOWER(Action) * All actions starting with 'z' apply to the zip file. * All actions starting with 'f' apply to the contents. IF Action = 'znew' This.cZipName = FileName ELSE IF EMPTY(This.cZipName) MESSAGEBOX('Can not find zip file '+This.cZipName) RETURN ELSE * Create/renew a Folder object. This.oFld = '' DO WHILE TYPE('This.oFld') <> 'O' This.oFld = This.oShell.NameSpace(This.cZipName) ENDDO ENDIF * Create/renew an Items object. This.oIts = '' =Sleep(This.nDelay) This.oIts = This.oFld.Items IF Action = 'f' AND Action <> 'fadd' * Find the file in the Zip. FOR t = 0 TO This.oIts.Count-1 IF This.oIts.Item[t].Name = FileName EXIT ENDIF ENDFOR IF t = This.oIts.Count MESSAGEBOX('Can not find '+FileName+' in '+This.cZipName) RETURN ENDIF ENDIF ENDIF DO CASE * Carry out Action on the zip file. CASE Action = 'znew' STRTOFILE('PK'+CHR(0x05)+CHR(0x06)+REPLICATE(CHR(0),18),FileName,0) CASE Action = 'zopen' This.oIts.Item.Verbs.Item[0].DoIt CASE Action = 'zsearch' This.oIts.Item.Verbs.Item[1].DoIt CASE Action = 'zextractto' This.oIts.Item.Verbs.Item[2].DoIt CASE Action = 'zexplore' This.oIts.Item.Verbs.Item[3].DoIt CASE Action = 'zextractall' This.oFld.Self.Verbs.Item(4).DoIt CASE Action = 'zscan' This.oFld.Self.Verbs.Item(5).DoIt CASE Action = 'zcut' This.oFld.Self.Verbs.Item(8).DoIt CASE Action = 'zcopy' This.oFld.Self.Verbs.Item(9).DoIt CASE Action = 'zshort' This.oFld.Self.Verbs.Item(10).DoIt CASE Action = 'zshort' This.oFld.Self.Verbs.Item(11).DoIt CASE Action = 'zrename' This.oFld.Self.Verbs.Item(12).DoIt CASE Action = 'zproperties' This.oFld.Self.Verbs.Item(13).DoIt * Carry out Action on the zip contents. CASE Action = 'fadd' This.oFld.CopyHere(FileName,0) CASE Action = 'fopen' This.oIts.Item(t).Verbs.Item(0).DoIt CASE Action = 'fcut' This.oIts.Item(t).Verbs.Item(1).DoIt CASE Action = 'fcopy' This.oIts.Item(t).Verbs.Item(2).DoIt CASE Action = 'fdelete' This.oIts.Item(t).Verbs.Item(3).DoIt CASE Action = 'fproperties' This.oIts.Item(t).Verbs.Item(4).DoIt OTHERWISE MESSAGEBOX('The action is not supported') ENDCASE ENDPROC ENDDEFINE