Platforms to show: All Mac Windows Linux Cross-Platform

Back to ZipMBS class.

ZipMBS.CompressFiles(ZipFile as FolderItem, SourceFolder as FolderItem, files() as string, Overwrite as Integer = 0, Password as string = "", CompressionLevel as Integer = 9, byref ErrorMessage as string) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Compression MBS Compression Plugin 16.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Simple implementation of a batch file compression method.
Example
dim f as FolderItem = SpecialFolder.Desktop.Child("test.zip")
dim folder as FolderItem = SpecialFolder.Pictures // some folder with images
dim files() As string

dim c as Integer = folder.count
for i as Integer = 1 to c
dim file as FolderItem = folder.TrueItem(i)

if file.Directory then
// we go here for this example only one level deep

dim subfolder as FolderItem = file
dim cc as Integer = subfolder.count
for ii as Integer = 1 to cc
dim subfile as FolderItem = subfolder.TrueItem(ii)
if subfile.name.Right(4) = ".jpg" then
// here we pass a relative path
files.Append subfolder.name+"/"+subfile.name
end if
next

else

if file.name.Right(4) = ".jpg" then
// just padd a file name for files directly in source folder
files.Append file.name
end if
end if
next

dim ErrorMessage as string
dim e as Integer = ZipMBS.CompressFiles(f, folder, files, errorMessage)

MsgBox "Error: "+str(e)

ZipFile: The destination zip file.
SourceFolder: The source folder for the files.
files: relative file paths to source folder.
Overwrite: pass 1 to overwrite zip archive, 2 to append or 0 to not overwrite.
Password: the password for encryption.
CompressionLevel: The compression level to use from 0 (no compression) to 9 (maximum).
ErrorMessage: An english error message.

Returns 0 on success or error code on failure.

This is a simple function to compress a couple of files.
It does not preserve file permissions on Mac/Linux or other metadata.
And it may not work with non ASCII characters.

If you need more control over files being added, compression or error checking, please use example projects coming with plugin.

Some examples using this method:

The items on this page are in the following plugins: MBS Compression Plugin.


The biggest plugin in space...