B4J Question Archiver

ThRuST

Well-Known Member
Licensed User
Longtime User
Anyone with experience with this library to unzip and zip a .zip file to a specified folder.
Was looking for a zip lib but noticed that it's available in B4J verson 6.00 and perhaps earlier.
Is it possible to set compression level and password protect an archive? Thanks
 

ThRuST

Well-Known Member
Licensed User
Longtime User
ok I will answer my own post with the solution. It will help everyone since I didn't find any post about the archiver so here's how you zip/unzip files with Archiver.

B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private BtnUnzip As Button
    Private BtnZip As Button
    Public Arc As Archiver
    Public Destination As String = "d:\zipped\unzip"
    Public Source As String = "d:\zipped\zip"
    Public ZipSource As String = "d:\zipped\unzip\images"
    Public ZipFile As String = ""
 
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Form1") 'Load the layout file.
    MainForm.Show
End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub BtnUnzip_Click
 
    Arc.UnZip(Source, "images.zip", Destination, Null)
 
End Sub

Sub BtnZip_Click
 
    Dim FilesToZip(2) As String
    FilesToZip(0) = "image1.png"
    FilesToZip(1) = "image2.png"
 
    Arc.ZipFiles(ZipSource, FilesToZip, Source, "newzip.zip", Null)
 
    ' Zip a folder
    'Arc.ZipFolder(Destination, Source, "myzip.zip", Null)
 
End Sub

Note that the null parameter I provided is the Events you can use to have more control. You'll see them when you dim archiver. images.zip goes into the source folder which is a zipped folder "images" that holds two images.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…