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:
This project has the following interface:
The buttons have the following actions:
buttonZipDemo
: Activates the procedure to zip, containing thezip
andpowerShell Compress-Archive
example above.Prepare download
: Download the zip file created by thebuttonZipDemo
buttonUnzipDemo
: Activates the procedure to unzip, containing theunzip
andpowerShell Expand-Archive
example above.buttonOverviewCopiedFiles
: Lists all files in the project folder, including the files expanded from the archive bybuttonUnzipDemo
Further Reading
Datalake storage download: dex::dls::DownloadFile
Datalake storage upload: dex::dls::UploadFile