(This function uses sys2.dbf which contains definitions of .dbf files, in this case I use it as a list of files to archive)
Code: Select all
function MakeBackup
param cArchiveFolder, cArchiveName
local CFileName
local cComment, cPassword
static lPendingArchivization := .f.
if lPendingArchivization
return
endif
lPendingArchivization := .t.
cPassword := 'you can give your password to zip file here'
cComment := "Archive from day: " + dtoc(date())+" "+time() +;
chr(13)+chr(10)+;
"Company: Your company name" +;
chr(13)+chr(10)+;
"Program FAKTURY (MOL-SK Marek Olszewski)"+;
chr(13)+chr(10)+;
"Version: "+ cApplicationVersion
if substr(cArchiveFolder,-1) <> "\"
cArchiveFolder += "\"
endif
if !file(cArchiveFolder+"nul")
CreateFolder(cArchiveFolder)
if !file(cArchiveFolder+"\nul")
MsgStop("Cannot create archive folder. Stopped!!!")
lPendingArchivization := .f.
return
endif
endif
cArchiveName := cArchiveFolder + cArchiveName + ".zip"
if file(cArchiveName)
if !MsgYesNo("Archive File already exists. Overwrite?","Overwrite archive file?",.t.)
lPendingArchivization := .f.
return
endif
endif
// database sys2 contains list of all .dbf files to archive
Use sys2 new
sys2->(DBGoTop())
hZip := HB_ZIPOPEN( cArchiveName )
if ! empty( hZip )
do while !sys2->(eof())
CFileName := alltrim(sys2->FileName)
if ascan(CFileName, ".") = 0
// filename does not contain extension
CFileName += ".dbf"
endif
HB_ZipStoreFile( hZip, cFileName, cFileName, cPassword )
sys2->(DBSkip())
enddo
sys2->(DBCloseArea())
HB_ZIPCLOSE( hZip, cComment )
endif
lPendingArchivization := .f.
return