Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
USER INTERFACES >>  HOW TO ADD A PROGRESS BAR TO A .ZIP OPERATION

  Chris Chamberlain
  Where is Chris Chamberlain?
 GL6 0PN
 United Kingdom
 Chris Chamberlain



If you need to add compression to a VFP app, look no further than Craig Boyd's excellent VFPcompression.fll.

Free and fast, documentation and download are available at http://www.sweetpotatosoftware.com/SPSBlog/CommentView,guid,07ed8874-8781-4e76-878b-92b3f4cfc8b3.aspx#commentstart

Under certain circumstances, it's possible to utilise the callback feature to populate a progress bar.

The purpose of this FAQ is to show how to use the callback function to gather the necessary data - the actual implementation of the progress bar is left to the individual developer.

The .prg that follows utilises the ZipFolderQuick() function - if you substitute your own folder for "tablesbackup", you can run the code and see how it works.

The two values required for a progress bar are :-

oZipData.nFiles2Zip
oZipData.nFileCount

So to calculate the percentage of files zipped, divide oZipData.nFileCount by oZipData.nFiles2Zip and multiply by 100

As well as populating the progress bar, the other values generated in the function, together with the use of ADIR(), Scripting.FileSystemObject, etc, may be used for form label captions such as:-

Current file being zipped and filesize
Last file zipped and filesize
Total files to zip
Total files zipped
Total bytes written

At the end of the operation, you can also display time taken for the operation, filesize of the .zip file and calculate compression percentage.

See also http://www.foxite.com/faq/default.aspx?id=59 - How can I cancel out of a zip operation

***********
CLEA
SET LIBRARY TO LOCFILE([vfpcompression.fll])

oZipData = CREATEOBJECT([Empty])
ADDPROPERTY(oZipData,[cZipObjectName],[])
ADDPROPERTY(oZipData,[nFileCount],0)
ADDPROPERTY(oZipData,[nFiles2Zip],0)
ADDPROPERTY(oZipData,[nBytesRead],0)
ADDPROPERTY(oZipData,[nTotalBytes],0)

oZipData.nFiles2Zip = ADIR(laTemp,[tablesbackup\*.*])
MESSAGEBOX([No of files to zip is ] + TRANSFORM(oZipData.nFiles2Zip))

ZipCallBack([ZipStatus()])
ZipFolderQuick(ADDBS(SYS(5) + SYS(2003)) + [tablesbackup],.F.)
ZipCallBack([])

RELEASE oZipData, laTemp
SET LIBRARY TO

*!* *!* *!* *!* *!* *!*
FUNCTION ZipStatus()
*!* *!* *!* *!* *!* *!*
DO CASE
CASE nZipEvent = 0
? [Opening ] + cObjectName
CASE nZipEvent = 2
oZipData.nBytesRead = nZipBytes
CASE nZipEvent = 5
? [Closing ] + cObjectName
CASE oZipData.cZipObjectName = cZipObjectName
? TRANSFORM(oZipData.nBytesRead) ;
+ [ bytes read]
CASE oZipData.cZipObjectName # cZipObjectName
oZipData.cZipObjectName = cZipObjectName
oZipData.nFileCount = oZipData.nFileCount ;
+ 1
oZipData.nTotalBytes = oZipData.nTotalBytes ;
+ oZipData.nBytesRead
? [Filename is ] ;
+ PROPER(LOWER(JUSTFNAME(cZipObjectName)))
? [Zipped files count is ] ;
+ TRANSFORM(oZipData.nFileCount)
? [Total bytes zipped is ] ;
+ TRANSFORM(oZipData.nTotalBytes)
? [Files zipped is ] ;
+ TRANSFORM(INT(oZipData.nFileCount / oZipData.nFiles2Zip * 100)) ;
+ [%]
ENDCASE

ENDFUNC
* EOF

Any suggestions for improvements always welcome

FEEDBACK


Your Name: 
Your Feedback: 

Spam Protection:
Enter the code shown: