iOS Question How do you zip up a particular file, not a directory

boredsilly

Member
Licensed User
Longtime User
Looking at iarchive doco it seems to require a source directory when using zipfolder and zips up the directory and its contents.

ZipFolder (InDir As String, OutArchiveFolder As String, OutArchiveName As String)

If I want to zip a single file and not any directory containing the file how would i do that?

Thanks.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this code to zip one file or more:
B4X:
'returns True if successful
Private Sub ZipFiles(Files As List, OutFolder As String, OutFileName As String) As Boolean
   Dim no As NativeObject
   Return no.Initialize("SSZipArchive").RunMethod("createZipFileAtPath:withFilesAtPaths:", _
     Array(File.Combine(OutFolder, OutFileName), Files)).AsBoolean
End Sub

Example:
B4X:
File.WriteString(File.DirTemp, "test.txt", "Sdfsdfsdf")
Log("Success = " & ZipFiles(Array (File.Combine(File.DirTemp, "test.txt")), File.DirLibrary, "1.zip"))
 
Upvote 0
Top