Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
Archive.Create
Creates a new archive.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
Archive | 13.1 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
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 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 empty or file name for container. |
"C:\test.zip" | 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 |
"compression-level=9¶hdrcharset=UTF-8" | Optional |
Password | The passphrase to use for password protection. Usually only used when an encryption option is set. |
"secret" | Optional |
Result
Returns OK or error.
Description
Creates a new archive.You may call Archive.AddContainer, Archive.AddFile and Archive.AddText to add files and later call Archive.Close function to finish.
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
Create a zip file on desktop:
Set Variable [ $r ; Value: MBS( "Archive.Create"; "zip"; "deflate"; "/Users/cs/Desktop/test.zip") ]
# add a file from desktop folder:
Set Variable [ $r ; Value: MBS( "Archive.AddFile"; "test.png"; "/Users/cs/Desktop") ]
# add a text file:
Set Variable [ $r ; Value: MBS( "Archive.AddText"; "Hello World!"; "UTF-8"; "test.txt") ]
# add something from container field:
Set Variable [ $r ; Value: MBS( "Archive.AddContainer"; Kontakte::Foto) ]
# and close file.
Set Variable [ $r ; Value: MBS( "Archive.Close") ]
Create a zip and store in container:
Set Variable [ $r ; Value: MBS( "Archive.Create"; "zip"; "deflate"; "test.zip") ]
# add file from desktop:
Set Variable [ $r ; Value: MBS( "Archive.AddFile"; "test.png"; "/Users/cs/Desktop") ]
# add a text file:
Set Variable [ $r ; Value: MBS( "Archive.AddText"; "Hello World!"; "UTF-8"; "test.txt") ]
# add a picture:
Set Variable [ $r ; Value: MBS( "Archive.AddContainer"; MyTable::MyPhoto) ]
# close and get the container value:
Set Variable [ $container ; Value: MBS( "Archive.Close") ]
# Store in a Field:
Set Field [ MyTable::MyZip ; $container ]
Commit Records/Requests [ With dialog: Off ]
Compress PDF containers into a zip file:
Set Variable [ $path ; Value: MBS( "Path.AddPathComponent"; MBS( "Folders.UserDesktop" ); "test.zip" ) ]
Set Variable [ $r ; Value: MBS( "Archive.Create"; "zip"; "deflate"; $path) ]
If [ MBS("IsError") ]
Show Custom Dialog [ "Failed to create zip archive." ; $r ]
Exit Script [ Text Result: ]
End If
#
Go to Record/Request/Page [ First ]
Set Variable [ $destPage ; Value: 1 ]
Loop
Set Variable [ $r ; Value: MBS( "Archive.AddContainer"; Merge PDFs::InputPDF) ]
Go to Record/Request/Page [ Next ; Exit after last: On ]
End Loop
Set Variable [ $r ; Value: MBS( "Archive.Close") ]
Create 7zip archive:
MBS( "Archive.Create"; "7zip"; ""; $path)
Create email with PDF and XML and add to email:
# get some XML and PDF
Set Variable [ $PDF ; Value: Reports::ReportContainer ]
Set Variable [ $XML ; Value: "<test>Hello Hello Hello</test>" ]
# Compress it
Set Variable [ $r ; Value: MBS( "Archive.Create"; "zip"; "deflate"; "export.zip"; "compression-level=9¶hdrcharset=UTF-8") ]
Set Variable [ $r ; Value: MBS( "Archive.AddText"; $xml; "UTF-8"; "export.xml") ]
Set Variable [ $r ; Value: MBS( "Archive.AddContainer"; $PDF) ]
Set Variable [ $Archive ; Value: MBS( "Archive.Close"; "report.zip" ) ]
# now add to email
Set Variable [ $email ; Value: MBS( "SendMail.CreateEmail") ]
Set Variable [ $r ; Value: MBS( "SendMail.AddAttachmentContainer"; $Email; $Archive; "report.zip"; "application/zip" ) ]
Set Variable [ $r ; Value: MBS( "SendMail.SetPlainText"; $email; "Dear " & Kontakte::Vorname & ¶ & ¶ & "Attached you find the export from " & Get(CurrentDate ) & ¶ & ¶ & "Greetings" & ¶ & "Your FileMaker Server") ]
See also
- Archive.AddContainer
- Archive.AddFile
- Archive.AddText
- Archive.Close
- Folders.UserDesktop
- IsError
- Path.AddPathComponent
- SendMail.AddAttachmentContainer
- SendMail.CreateEmail
- SendMail.SetPlainText
Release notes
- Version 13.2
- Fixed a problem with Archive.Create and creating 7zip archive.
- Version 13.1
- Added Archive.Create, Archive.AddContainer, Archive.AddFile, Archive.AddText and Archive.Close functions.
Example Databases
Blog Entries
- Compress and Send
- MBS FileMaker Plugin, version 13.2pr1
- New in MBS FileMaker Plugin 13.1
- Build archives on the fly
- MBS FileMaker Plugin, version 13.1pr3
FileMaker Magazin
This function checks for a license.
Created 13th February 2023, last changed 4th July 2024