Zipping and Unzipping on AIMMS Developer and on AIMMS Cloud

Downloading and uploading a collection of files is achieved by first compressing into a single file, called an archive, and then transferring the archive from one machine to the other. In this article, we will focus on the compression of a collection of files into a single archive, and on the expansion of such an archive into a collection of files.

The AIMMS core does not provide zipping and unzipping functionality natively; but

  • Windows 10 and Windows 11 provide the powershell commands Compress-Archive and Expand-Archive

  • Most Linux distributions, including the Linux distribution used on the AIMMS Cloud, provide zip. The use of zip is illustrated here

This can be leveraged using the Execute procedure of AIMMS, for instance to create a zip archive as follows:

1    if AimmsStringConstants('Platform') = "Linux" then
2            Execute( "zip", "-r " + sp_destinationFile + " " + sp_folderName , wait:1) ;
3    else
4            Execute( "powershell \"Compress-Archive -Path "+ sp_folderName+" -DestinationPath "+sp_destinationFile+"\"", wait:1);
5    endif ;

and to unpack such a zip archive into files as follows:

1    if AimmsStringConstants('Platform') = "Linux" then
2            Execute( "unzip", sp_fileName + " -d " + sp_destinationFolderName , wait:1) ;
3    else
4            Execute( "powershell \"Expand-Archive -Path "+ sp_fileName+" -DestinationPath "+sp_destinationFolderName+"\"", wait:1);
5    endif ;

The above is captured in an example project that can be obtained via the download:

AIMMS 24.2 project download

This project has the following interface:

../../_images/zipunzip-app.png

The buttons have the following actions:

  1. buttonZipDemo: Activates the procedure to zip, containing the zip and powerShell Compress-Archive example above.

  2. Prepare download: Download the zip file created by the buttonZipDemo

  3. buttonUnzipDemo: Activates the procedure to unzip, containing the unzip and powerShell Expand-Archive example above.

  4. buttonOverviewCopiedFiles: Lists all files in the project folder, including the files expanded from the archive by buttonUnzipDemo

Further Reading