Archive.Compress
----------------

Compresses files to an archive.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [Archive](component_Archive.md) | [9.0](newinversion90.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "Archive.Compress"; Format; Filter; Destination; BasePath { ; List; Options; Password } ) 

**MBS**( **"Archive.Compress";** /\* Compresses files to an archive. \*/  
**$Format**; /\* The format to use.  
Formats: ar, arbsd, argnu, arsvr4, bsdtar, cd9660, cpio, gnutar, iso, iso9660, mtree, mtree-classic, newc, odc, oldtar, pax, paxr, posix, raw, rpax, shar, shardump, ustar, v7tar, v7, warc, xar, zip.e.g. "zip" \*/   
**$Filter**; /\* The filter to use.  
For zip format can be store, bzip2, zstd or deflate.  
Filters: b64encode, bzip2, compress, grzip, gzip, lrzip, lz4, lzip, lzma, lzop, uuencode, xz, zstd.  
  
Not all filters can be combined with all formats.e.g. "deflate" \*/   
**$Destination**; /\* The native file path to the destination archive.  
Or file name for container.e.g. "C:\\test.zip" \*/   
**$BasePath**; /\* The bath path to the folder where to look for files.e.g. "C:\\test" \*/   
**$List**; /\* Optional; the list of files and folders to add to archive.  
If empty, we compress base path as item.e.g. "test.txt" \*/   
**$Options**; /\* Optional; The options to pass to writer.  
This is a comma-separated list of options. Option names can be prefixed with module name.  
  
Sample options:   
compression-level=9  
zip:encryption=zipcrypt  
zip:encryption=aes128  
zip:encryption=aes256  
zip64  
gzip:compression-level=9  
hdrcharset=UTF-8e.g. "zip:encryption=zipcrypt" \*/   
**$Password**) /\* Optional; The passphrase to use for password protection.e.g. "secret" \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| Format | The format to use.   Formats: ar, arbsd, argnu, arsvr4, bsdtar, cd9660, cpio, gnutar, iso, iso9660, mtree, mtree-classic, newc, odc, oldtar, pax, paxr, posix, raw, rpax, shar, shardump, ustar, v7tar, v7, warc, xar, zip. | "zip" |  |
| Filter | The filter to use.   For zip format can be store, bzip2, zstd or deflate.   Filters: b64encode, bzip2, compress, grzip, gzip, lrzip, lz4, lzip, lzma, lzop, uuencode, xz, zstd.      Not all filters can be combined with all formats. | "deflate" |  |
| Destination | The native file path to the destination archive.   Or file name for container. | "C:\\test.zip" |  |
| BasePath | The bath path to the folder where to look for files. | "C:\\test" |  |
| List | the list of files and folders to add to archive.   If empty, we compress base path as item. | "test.txt" | Optional |
| Options | The options to pass to writer.   This is a comma-separated list of options. Option names can be prefixed with module name.      Sample options:    compression-level=9   zip:encryption=zipcrypt   zip:encryption=aes128   zip:encryption=aes256   zip64   gzip:compression-level=9   hdrcharset=UTF-8 | "zip:encryption=zipcrypt" | Optional |
| Password | The passphrase to use for password protection. | "secret" | Optional |

### Result

Returns OK, container or error.

### Description

Compresses files to an archive.  
Supports various compression algorithms and encryption.  
The archive usually should not contain the absolute paths of the files, so we need a base path and relative to that base path the list of files and folders to zip.   
### Examples

Compression examples:

 # list of files in the folder to archive   
Set Variable \[ $list ; Value: "minitar.c¶simplebar.rbp¶test/other.txt" \]   
  
\# write zip file with password   
Set Variable \[ $r ; Value: MBS ( "Archive.Compress"; "zip"; "deflate"; "/Users/cs/Desktop/minitar.zip"; "/Users/cs/Desktop/"; $list ; "zip:encryption=zipcrypt"; "secret password" ) \]   
  
\# Write bzip2 compress tar file:   
Set Variable \[ $r ; Value: MBS ( "Archive.Compress"; "ustar"; "bzip2"; "/Users/cs/Desktop/minitar.tar"; "/Users/cs/Desktop/") \]   
  
\# and write zip with aes encryption to container file:   
Set Variable \[ $r ; Value: MBS ( "Archive.Compress"; "zip"; "deflate"; "minitar.zip"; "/Users/cs/Desktop/"; $list ; "zip:encryption=aes128"; "secret password" ) \]   
Set Field \[ Archive Read::Container ; $r \]  
Compress with UTF-8 file names:

 MBS ( "Archive.Compress"; "zip"; "deflate"; "C:\\Users\\Christian\\Desktop\\test.zip"; "C:\\Users\\Christian\\Desktop"; "Bücher"; "hdrcharset=UTF-8" )  
Compress content of logs folder on server:

 # the path to logs folder   
Set Variable \[ $folder ; Value: "/opt/FileMaker/FileMaker Server/Logs" \]   
\# query list of files   
Set Variable \[ $list ; Value: MBS ( "[Files.List](FilesList.md)"; $folder ) \]   
\# where to store the zip file:   
Set Variable \[ $ZipPath ; Value: MBS ( "[Path.AddPathComponent](PathAddPathComponent.md)"; "/tmp"; "test.zip") \]   
\# and now zip these files:   
Set Variable \[ $archive ; Value: MBS ( "Archive.Compress"; "zip"; "deflate"; $ZipPath ; $folder ; $list ; "compression-level=9¶hdrcharset=UTF-8") \]  
Compress a file in a let statement:

 Let(\[  
filename = "test.jpg";  
SourcePath = MBS ("[Folders.UserDesktop](FoldersUserDesktop.md)");  
DestPath = MBS ("[Path.AddPathComponent](PathAddPathComponent.md)"; MBS ("[Folders.UserTemporary](FoldersUserTemporary.md)"); "test.zip");  
r = MBS ( "Archive.Compress"; "zip"; "deflate"; DestPath; SourcePath; filename; "zip:encryption=zipcrypt¶hdrcharset=UTF-8"; "12345" )  
\];r)  
Compress with hashed password:

 Let(\[  
 filename = "test.jpg";  
 password = MBS ( "[Hash.SHA256](HashSHA256.md)"; "testing" ) ;  
 SourcePath = MBS ("[Folders.UserDesktop](FoldersUserDesktop.md)");  
 DestPath = MBS ("[Path.AddPathComponent](PathAddPathComponent.md)"; MBS ("[Folders.UserTemporary](FoldersUserTemporary.md)"); "test.zip");  
 r = MBS ( "Archive.Compress"; "zip"; "deflate"; DestPath; SourcePath; filename; "zip:encryption=zipcrypt¶hdrcharset=UTF-8"; password)  
\];r)  
Compress whole folder:

 MBS ( "Archive.Compress"; "zip"; "deflate"; "/Users/cs/Temp.zip"; "/Users/cs"; "Temp"; "hdrcharset=UTF-8" )  
Compress files in folder on desktop:

 Set Variable \[ $DesktopFolder ; Value: MBS ( "[Folders.UserDesktop](FoldersUserDesktop.md)" ) \]  
Set Variable \[ $Folder ; Value: MBS ( "[Path.AddPathComponent](PathAddPathComponent.md)"; $DesktopFolder ; "Island Fotos" ) \]  
Set Variable \[ $ZipPath ; Value: MBS ( "[Path.AddPathComponent](PathAddPathComponent.md)"; $DesktopFolder ; "Island Fotos.zip" ) \]  
Set Variable \[ $list ; Value: MBS ("[Files.List](FilesList.md)"; $Folder ) \]  
Set Variable \[ $r ; Value: MBS ( "Archive.Compress"; "zip"; "deflate"; $ZipPath ; $Folder ; $list ; "hdrcharset=UTF-8" ) \]  
### See also

- [Archive.CompressContainer](ArchiveCompressContainer.md)
- [Archive.CompressText](ArchiveCompressText.md)
- [Files.List](FilesList.md)
- [Folders.UserDesktop](FoldersUserDesktop.md)
- [Folders.UserTemporary](FoldersUserTemporary.md)
- [Hash.SHA256](HashSHA256.md)
- [Path.AddPathComponent](PathAddPathComponent.md)
- [ZipFile.CompressFiles](ZipFileCompressFiles.md)
- [ZipFile.CreateFile](ZipFileCreateFile.md)
- [ZipFile.Open](ZipFileOpen.md)

### Release notes

- **Version 15.3**
    - Added bzip2 and zstd as filter for zip archives for [Archive.Compress](https://www.mbsplugins.eu/ArchiveCompress.shtml), [Archive.CompressContainer](https://www.mbsplugins.eu/ArchiveCompressContainer.shtml), [Archive.CompressText](https://www.mbsplugins.eu/ArchiveCompressText.shtml) and [Archive.Create](https://www.mbsplugins.eu/ArchiveCreate.shtml) functions.
- **Version 15.2**
    - Fixed [Archive.Compress](https://www.mbsplugins.eu/ArchiveCompress.shtml) to better compress folder itself if file list is empty.
    - Improved [Archive.Compress](https://www.mbsplugins.eu/ArchiveCompress.shtml) to compress folder itself if file list is empty.
- **Version 14.3**
    - Added [Archive.CompressText](https://www.mbsplugins.eu/ArchiveCompressText.shtml) function.
- **Version 11.1**
    - Added [Archive.CompressContainer](https://www.mbsplugins.eu/ArchiveCompressContainer.shtml) function.
- **Version 9.1**
    - Fixed bug with [Archive.Compress](http://www.mbsplugins.eu/ArchiveCompress.shtml) not writing file on Windows.

### Blog Entries

- [MBS FileMaker Plugin, version 15.3pr5](https://www.mbsplugins.de/archive/2025-07-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 15.2pr3](https://www.mbsplugins.de/archive/2025-04-10/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 15.2pr1](https://www.mbsplugins.de/archive/2025-04-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 9.1pr4](https://www.mbsplugins.de/archive/2019-02-25/MBS_FileMaker_Plugin_version_9/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 4/2023, Seite 38](https://filemaker-magazin.de/neuigkeit/4233-Appetithappen-FMM_202304)

This function checks for a license.

Created 17th December 2018 , last changed 10th July 2025

  
[Archive.Close](ArchiveClose.md) - [Archive.CompressContainer](ArchiveCompressContainer.md)

[HTML Version](ArchiveCompress.shtml)