INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Utility Program

How to create ZIP Files with VFP by craigsboyd
Posted: 4 Jul 03 (Edited 18 Feb 05)

Slighthaze = NULL

*!* The following shows a Backup aand Restore scenario
*!* But the code could be modified to ZIP any files or UNZIP any zip file
*!* Backup and Restore is just one of the possible uses in your VFP project
*!* IMPORTANT: SAWZip.dll must be registered on your computer for any of this to work
*!* Get it at: http://www.codeproject.com/atl/sawzip.asp
*!* If this link becomes broken at some point email me at craig@sweetpotatosoftware.com
*!* Cut and paste this code into a prg and run it from within VFP when you are ready


LOCAL cZipfile, cBackupPath,cRestorePath, cMask
cZipfile = ADDBS(SYS(2023)) + "_"+SUBSTR(SYS(2015), 4)  + ".zip" && Zip will be in your Windows Temp Directory
cMask = "*.*"
cBackupPath = GETDIR("C:\","Select directory to backup","BACKUP DIRECTORY?",64)
cRestorePath = GETDIR("C:\","Select where to restore","RESTORE DIRECTORY?",64)
IF !DIRECTORY(cBackupPath) OR !DIRECTORY(cRestorePath)
    MESSAGEBOX("Both a backup directory and a restore directory must be selected",16,"Missing directory")
    RETURN
ENDIF

*!*    ZIPPING WHOLE DIRECTORY
WAIT WINDOW "BACKING UP FILES WITH PROGRESS INDICATION...  ONE MOMENT PLEASE" NOWAIT
oSAWArchive = CREATEOBJECT("SAWZip.Archive")
oSAWArchive.Create(cZipfile)
Local lcPath, cZippedFile, nProgressValue, nProgressMax
cZippedFile = Sys( 2000,cBackupPath+cMask)
nProgressMax=ADIR(aryFiles,cBackupPath+cMask)
RELEASE aryFiles
nProgressValue= 1
Do While !Empty( cZippedFile )
    oSAWFile = CREATEOBJECT("SAWZip.File")
    oSAWFile.FullPath = .f.
    oSAWFile.Name = cBackupPath+cZippedFile
        nProgressComplete = INT(nProgressValue/nProgressMax*100)
    sMessage = "BACKING UP: " + TRANSFORM(nProgressComplete)+"% " + Replicate("|",INT(nProgressComplete/2))
    set message to sMessage
    oSAWArchive.Files.Add(oSAWFile)
    oSawFile = .NULL.
    cZippedFile = Sys( 2000,cBackupPath+cMask,1)
    nProgressValue = nProgressValue + 1
Enddo
oSAWArchive.close
oSAWArchive = .NULL.
WAIT CLEAR
MESSAGEBOX("Backup Completed")

*!*    UNZIPPING WHOLE DIRECTORY
WAIT WINDOW "RESTORING FILES WITH PROGRESS INDICATION...  ONE MOMENT PLEASE" NOWAIT
LOCAL cFileExtracted
oSAWArchive = CREATEOBJECT("SAWZip.Archive")
oSAWArchive.Open(cZipfile)
oSAWFile = CREATEOBJECT("SAWZip.File")
nProgressMax=oSAWArchive.Files.count
nProgressValue= 1
FOR EACH oSAWFile IN oSAWArchive.Files
    cFileExtracted = oSAWFile.Extract(cRestorePath)
         nProgressComplete = INT(nProgressValue/nProgressMax*100)
    sMessage = "RESTORING: " +TRANSFORM(nProgressComplete) +"% " + Replicate("|",INT(nProgressComplete/2))
    set message to sMessage
    nProgressValue = nProgressValue + 1
endfor
oSAWArchive.close
oSAWArchive = .NULL.
WAIT CLEAR
MESSAGEBOX("Restore Completed")

IF MESSAGEBOX("Do you wish to delete the zip file listed below now?" + CHR(13) + CHR(13) +;
        cZipfile + CHR(13) + CHR(13) +;
        "If you will be deleting it manually then click NO", 36, "DELETE TEMP ZIP?") = 6
    ERASE (cZipfile)
ENDIF

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close