B4J Library SD: ZipLibrary

jSD_ZipLibray

Author:
Star-Dust
Version: 1.02
  • SD_ZipLibray
    • Functions:
      • Class_Globals As String
      • Initialize As String
        Inizializza l'oggetto. Puoi aggiungere parametri a questo metodo,se necessario.
      • IsInitialized As Boolean
        Verifica se l'oggetto sia stato inizializzato.
      • Zip (FilesTxt As String(), FileZip As String)
      • unZip (FilesZip As String, OutPutFolder As String)
      • unZipList (FilesZip As String, OutPutFolder As String) As List
ZIP
B4X:
Dim ZL As SD_ZipLibray

ZL.Initialize
ZL.Zip(ListFiles,ZipFileName)

UnZip
B4X:
Dim UnZL As SD_ZipLibray

    UnZL.Initialize
    UnZL.unZip(ZipFileName,FolderDestination)


N.B. When you choose the folder where to save the ZIP file, make sure it is a folder that you have write permission
 

Attachments

  • sample1.zip
    3.1 KB · Views: 812
  • jSD_ZipLibray 1.02.zip
    3.6 KB · Views: 873
  • SD_ZipLibray.bas
    3.8 KB · Views: 463
Last edited:

Peter Simpson

Expert
Licensed User
Longtime User
This is perfect for my next project.

Thank you...
 

Star-Dust

Expert
Licensed User
Longtime User
Done
 

Star-Dust

Expert
Licensed User
Longtime User
Sorry, I had put the version for Android. Now it's correct
 

m4.s

Member
Licensed User
Longtime User
This is also just what I've been trying to find for use within my B4J project!

However, in my case, I need to be able to ZIP one or more files in a source folder plus at least one of its sub-folders (with all its files); and then UnZIP both the root-level files and its sub-folder (inherently with all the files it contains) to another location.

Example:

Selected files for ZIPing
C:\MyFolder\File1.xml
C:\MyFolder\File2.png
C:\MyFolder\MySubFolder (containing these 2 files: File3.doc and File4.pdf)


UnZIPed to C:\aDiffFolder
yielding ->
C:\aDiffFolder\File1.xml
C:\aDiffFolder\File2.png
C:\aDiffFolder\MySubFolder\File3.doc
C:\aDiffFolder\MySubFolder\File4.pdf​


Further, if one or more of the extracted files and/or subfolders already exists, could it/they be overwritten with and without prompting?

Would you be able to add such support to your library?
 

Star-Dust

Expert
Licensed User
Longtime User
The library will not receive updates for the moment, I have no time. I'm sorry.
 

Star-Dust

Expert
Licensed User
Longtime User
NEW
I decided to make public the code with which I written this library. Use some java code, I think it can help the community understand how to use java (I know very little about it) inside b4x and maybe develop their own libraries.

Find the .BAS file with the source at the first post
 
Last edited:

Aldo's

Active Member
Licensed User
Does this library allow you to know the list of files contained in a zip file?
 

Star-Dust

Expert
Licensed User
Longtime User
Yes
 

Star-Dust

Expert
Licensed User
Longtime User
In post # 1 all the methods of the class are described. They are inserted to allow how to use the class. Also find an example
 

Aldo's

Active Member
Licensed User
another question: can you create a password protected zip file?
 

Star-Dust

Expert
Licensed User
Longtime User
another question: can you create a password protected zip file?
Not in this library. But I have attached the sources and you can edit for the function you need
 

Aldo's

Active Member
Licensed User

rtek1000

Active Member
Licensed User
Longtime User
Hello,

It works for files, but for folders there is an error: Access is denied

How can folders and files be compressed together?

I'm trying to zip an xlsx file that was unzipped with 7zip.

java.io.FileNotFoundException: C:\Datalogger_XLSX_Test\_rels (Access is denied)
at java.base/java.io.FileInputStream.open0(Native Method)
at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
at java.base/java.io.FileInputStream.<init>(FileInputStream.java:112)
at b4j.example.sd_ziplibray.ZipCompress(sd_ziplibray.java:91)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
at b4j.example.sd_ziplibray._zip(sd_ziplibray.java:71)
at b4j.example.main._button1_click(main.java:85)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109)
at anywheresoftware.b4a.BA$1.run(BA.java:234)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
 
Top