Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Zip Zip Hurray
Message
From
02/03/2004 17:47:18
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Title:
Zip Zip Hurray
Miscellaneous
Thread ID:
00882532
Message ID:
00882532
Views:
74
There have been a number of postings such as message#859913 and message#880426, noting that XP has a built in facility to handle Zip files and asking how to deal with them from within VFP.

I think I may have solved the problem (crossed fingers).

The code below works for me. How about you?
* Create an object to handle the zip file
oZHandler = CREATEOBJECT('ZipHandler')

* Create an empty zip file called test.zip in C:\temp
STRTOFILE('PK'+CHR(0x05)+CHR(0x06)+REPLICATE(CHR(0),18),'C:\temp\test.zip',0)

* Create text files to play with
STRTOFILE('Rubbish','C:\temp\fred.txt',0)
STRTOFILE('More rubbish','C:\temp\joe.txt',0)

SET STEP ON
* Step over each line to see results

WITH oZHandler

   * Place the two text files in the zip file
   .ZipName = 'C:\temp\test.zip'
   .AddToZip('C:\temp\fred.txt')
   .AddToZip('C:\temp\joe.txt')

   * Explore contents of the zip file
   .ExpZip()

   * View contents of the zip file
   .ViewZip()

   * Search contents of a zip file
   .SearchZip()

   * View contents of a text file
   .OpenFile('fred.txt')

   * Remove a file from the zip file
   .DelFromZip('joe.txt')

   * Remove next file from zip file
   .DelFromZip('fred.txt')

ENDWITH

RELEASE oZHandler

DEFINE CLASS ZipHandler AS Custom

   ZipName = ''

   PROCEDURE Init
      lcLibHome= HOME(1)+'Gallery\_webview.vcx'
      SET CLASSLIB TO (lcLibHome)
      This.AddObject('oFrm','Form')
      This.oFrm.AddObject('oZip','_webbrowser4')
   ENDPROC

   PROCEDURE ZipName_Assign
   LPARAMETERS vNewVal

      This.ZipName = M.vNewVal
      This.oFrm.oZip.Navigate(This.ZipName)

   ENDPROC

   PROCEDURE AddToZip
   LPARAMETERS FileToAdd

      oDoc = This.oFrm.oZip.Document
      oFld = oDoc.Folder
      oFld.CopyHere(FileToAdd,0)

   RETURN

   PROCEDURE ExpZip

      oDoc = This.oFrm.oZip.Document
      oFld = oDoc.Folder
      oIts = oFld.Items
      oIts.Item.Verbs.Item[3].DoIt

   RETURN

   PROCEDURE ViewZip
   
      oDoc = This.oFrm.oZip.Document
      oFld = oDoc.Folder
      oIts = oFld.Items
      oIts.Item.Verbs.Item[0].DoIt

   RETURN

   PROCEDURE SearchZip

      oDoc = This.oFrm.oZip.Document
      oFld = oDoc.Folder
      oIts = oFld.Items
      oIts.Item.Verbs.Item[1].DoIt
   
   RETURN

   PROCEDURE OpenFile
   LPARAMETERS FileToOpen

      oDoc = This.oFrm.oZip.Document
      oFld = oDoc.Folder
      oIts = oFld.Items
      nIts = oIts.Count
      FOR t = 0 TO nIts-1
         IF oIts.Item[t].Name = FileToOpen
            EXIT
         ENDIF
      ENDFOR
      oits.Item(t).Verbs.Item(0).DoIt

   RETURN

   PROCEDURE DelFromZip
   LPARAMETERS FileToDel

      oDoc = This.oFrm.oZip.Document
      oFld = oDoc.Folder
      oIts = oFld.Items
      nIts = oIts.Count
      FOR t = 0 TO nIts-1
         IF oIts.Item[t].Name = FileToDel
            EXIT
         ENDIF
      ENDFOR
      oits.Item(t).Verbs.Item(3).DoIt
   
   RETURN

ENDDEFINE
Next
Reply
Map
View

Click here to load this message in the networking platform