Skip to content

Latest commit

 

History

History
84 lines (52 loc) · 3.4 KB

580-download-compressed-files.rst

File metadata and controls

84 lines (52 loc) · 3.4 KB

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 :any:`Execute` procedure of AIMMS, for instance to create a zip archive as follows:

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

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

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

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

:download:`AIMMS 24.2 project download <model/ZipUnzip.zip>`

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

.. spelling:word-list::

        powershell