Android Question How to zip a folder in the one choosen by the user via ExternalStorage library

Sergio83

Active Member
Licensed User
Longtime User
Hello everyone and happy new year 2025!

I am facing a problem in the simultaneous use of EXTERNALSTORAGE and ARCHIVER libraries.
My goal is to zip a folder which is in DirRootexternal into the folder choosen by the user via the ExternalStorage library. But the asyncZipFolder method of the archiver does not accept the ExternalFile type.

More simply, how to convert an ExternalFile object type into a full path string?

I couldn't find a way to do it by looking on the forum...
Thanks in advance for your help
 

Sergio83

Active Member
Licensed User
Longtime User
Hello Erel,
Thanks for your reply, I had a feeling about its content and had already considered implementing it.
I didn't use it because it is a bit expensive in terms of memory space.
But I think I'll have to do it...
 
Upvote 0

Sergio83

Active Member
Licensed User
Longtime User
I tried to do what Erel poposed me:
B4X:
Sub unzip_domus(arcname As String)
    Private InStream As InputStream
    Private OutStream As OutputStream
    Private path_archive As ExternalFile
    
    ' Notifie le status maintenance du serveur
    Starter.maintenance=True
    
    ' Copie du ZIP dans DirInternal
    OutStream=File.Openoutput(File.dirinternal, archive_name,False)
    path_domusbup=Storage.FindDirOrCreate(Storage.Root,"domusbup")
    path_archive=Storage.Findfile(path_domusbup,archive_name)
    InStream=Storage.OpeninputStream(path_archive)
    File.Copy2(InStream,OutStream)
    Arc.UnZip(File.dirinternal,archive_name,File.dirrootexternal,"unzip")
    File.Delete(File.DirInternal,archive_name)
    
End Sub

But when executing:

B4X:
OutStream=File.Openoutput(File.dirinternal, archive_name,False)

I got this error message

B4X:
java.lang.RuntimeException: java.io.FileNotFoundException: /data/user/0/Domus.SeriSyvis/files (Is a directory)


I'm probably wrong somewhere but where?

PS I'm aware that DirRootExternal access will be no longer available depending of Android version used.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…