Improved the functions,
now it will accept an optional parameter to specify if hidden or system-files etc. shall be included to the package.
'just the new functions- no example... finally does the same as above.
Uses "FILE", "ZLIB"
' ---------------------------------------------------------------------
Function ZLib_PackFolder(ByVal sFolder As String, _
Optional ByVal sZipfilename As String, _
ByVal lFileTypes As Long = %FILE_NORMAL
) As Boolean
' ---------------------------------------------------------------------
' this is the function to call for the user
' sFolder: full path to the folder to pack as zip
' sZipfilename: full path & filename
' if omitted the folders name
' will be taken and ".zip" gets appended
' lFileTypes: combination of one or more FILE-module-equates
' only these are accepted/make sense:
' %FILE_NORMAL
' %FILE_READONLY
' %FILE_HIDDEN
' %FILE_SYSTEM
' %FILE_ARCHIVE
' it will pack a complete folder in one go
' -existing old zip-file will be deleted-
' this is NOT to ADD anything
Local lCheck As Long
If Not DIR_Exists(sFolder) Then Return FALSE
If Len(sZipFilename) = 0 Then
sZipFilename = Trim$(sFolder, "\") & ".zip"
EndIf
If RIGHT$(sFolder, 1) <> "\" Then
sFolder &= "\"
EndIf
If FILE_Exists(sZipFilename) Then
FILE_Kill(sZipfilename)
EndIf
' local check for valid flagged filetypes:
If (lFileTypes And %FILE_NORMAL) Then lCheck = %FILE_NORMAL
If (lFileTypes And %FILE_READONLY) Then lCheck = lCheck Or %FILE_READONLY
If (lFileTypes And %FILE_HIDDEN) Then lCheck = lCheck Or %FILE_HIDDEN
If (lFileTypes And %FILE_SYSTEM) Then lCheck = lCheck Or %FILE_SYSTEM
If (lFileTypes And %FILE_ARCHIVE) Then lCheck = lCheck Or %FILE_ARCHIVE
' start with the initial directory:
ZLib_AddSubDir(sZipfilename, sFolder, lCheck)
' close the zip finally
ZLib_AddEx(sZipfilename, "", %ZLIB_CLOSE)
' (ZLib_AddEx: helpfile is wrong here, it must be %ZLIB_, not %ZIP_)
' do we have data?
Function = (FILE_Size(sZipFilename) > 0)
End Function
' ---------------------------------------------------------------------
Function ZLib_AddSubDir(ByVal sZipfilename As String, _
ByVal sDir As String, _
ByVal lFileTypes As Long )
' ---------------------------------------------------------------------
' this function will add a subdir and all files inside that meet
' the specified type (usual %FILE_Normal) to a zipfile
' it gets called from the function above if all is ok and then calls
' itself until all data is added to the zip
' it will not copy empty directories into a zip !
Local sFile() As String
Local sPath() As String
Local nFiles As Long = DIR_ListArray(sFile, sDir, "*.*", lFileTypes )
Local nDirs As Long = DIR_ListArray(sPath, sDir, "*", %FILE_SUBDIR )
Local i As Long
If nFiles Then
For i = 1 To nFiles
ZLib_AddEx(sZIPFileName, sDir & sFile(i), %ZLIB_REL_PATH )
Next
EndIf
' calls itself:
If nDirs Then
For i = 1 To nDirs
ZLib_AddSubDir(sZipFilename, sDir & sPath(i) & "\", lFileTypes )
Next
EndIf
End Function
Bookmarks