Problem
You need to compress an entire folder into a single ".zip" file.
Solution
Use JMP's built-in support for compressing files to create a ZipArchive object. Once you have a ZipArchive object, you can write blob representations of the uncompressed files to the ".zip" file.
zipFolder = Function( {folderToZip, zipFileLoc, overwriteFile = 0, recursive = 1},
{Default Local},
If( Host is( "Windows" ),
folderToZip = Convert File Path( folderToZip, "Windows" );
zipFileLoc = Convert File Path( zipFileLoc, "Windows" );
If( Substr( folderToZip, -1 ) != "\",
folderToZip = Concat( folderToZip, "\" )
);
,
folderToZip = Convert File Path( folderToZip, "posix" );
zipFileLoc = Convert File Path( zipFileLoc, "posix" );
If( Substr( folderToZip, -1 ) != "/",
folderToZip = Concat( folderToZip, "/" )
);
);
If( File Exists( zipFileLoc ),
Match( overwriteFile,
0,
Write( "\!NFile already exists" );
Return( 0 );
,
1,
Delete File( zipFileLoc ),
);
);
za = Open( zipFileLoc, zip );
If( recursive == 1,
dirlist = Files In Directory( folderToZip, "recursive" ),
dirlist = Files In Directory( folderToZip )
);
For( iFile = 1, iFile <= N Items( dirlist ), iFile++,
tmpBlob = Load Text File( folderToZip || dirlist[iFile], blob );
za << Write( dirlist[iFile], tmpBlob );
);
Return( 1 );
);
Discussion
I've used variations of this function in several add-ins. Hopefully this will get you started with compressing your files!
See Also
JSL Syntax Reference > JSL Messages > Other Objects > Zip Archive
Scripting Index > ZipArchive