[color green]*!* 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[/color]
LOCAL cZipfile, cBackupPath,cRestorePath, cMask
cZipfile = ADDBS(SYS(2023)) + "_"+SUBSTR(SYS(2015), 4) + ".zip" [color green]&& Zip will be in your Windows Temp Directory[/color]
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
[color green]*!* ZIPPING WHOLE DIRECTORY[/color]
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")
[color green]*!* UNZIPPING WHOLE DIRECTORY[/color]
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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.