zip compress

Prev Next

Function Names

zip compress

Library

Zip Library

Description

This function compresses a file or directory with all the contents into a ZIP file.

Call as: procedure

Restrictions

Under normal conditions, the 'Zip Library' is loaded automatically, so no 'include(...)' call is needed.

Parameter count

1-3

Parameters

No.TypeDescription
1.
input
string Source path name

Choice of file or directory name. If directory name is chosen, then the whole directory with all contents will be compressed. Wildcards e.g. (pictures\*.jpg) are allowed. In this case, 2nd parameter (Archive file name) is also required to provide a concrete archive name.

Opt. 2.
input
string Archive file name

A dedicated archive file name is required if the 1st parameter does not specifcy a dedicated file or directory (with files inside), but to multiple files or directories (using wildcard symbols).

Opt. 3.
input
string Archive format

One of the following: zip and 7z (latter applies for 7-Zip and is supported under Windows only. Will be rejected under other operating systems").

Examples

      include( Zip Library );

      zip compress( "Examples\Cities.csv" );
      zip compress( "Examples\*.csv", "All csv.zip" );

      a[] = search files( "*.zip" );
      echo("Found following ZIP files: ", a[]);

      zip extract all( "All csv.zip" );

      echo("List the extracted contents from 'All csv.zip':", new line);
      directory listing recursive( d, "All csv" );
      table keep columns( d, {Path,Name,Date Created,Directory,Size} );
      table list( d );

      directory delete recursive ( "", "All csv" );
      file delete( "All csv.zip" );
      file delete( "Cities.zip" );

Output

Found following ZIP files: {'All csv.zip','Cities.zip'}
List the extracted contents from 'All csv.zip':

    0 : Path              | Name                               | Date Created | Directory | Size
    1 : All csv\          | Examples\                          | 2024-07-14   | Yes       | 0   
    2 : All csv\Examples\ | Cities.csv                         | 2024-02-11   | No        | 1035
    3 : All csv\Examples\ | Soccer Membership List.csv         | 2024-02-11   | No        | 431
    4 : All csv\Examples\ | Table Explore Demo.csv             | 2024-02-11   | No        | 472
    5 : All csv\Examples\ | Table Lookup Example 1.csv         | 2024-02-11   | No        | 542
    6 : All csv\Examples\ | Table Lookup Example 2.csv         | 2024-02-11   | No        | 571
    7 : All csv\Examples\ | Table Merge Examples Hillboro.csv  | 2024-02-11   | No        | 294
    8 : All csv\Examples\ | Table Merge Examples Hillville.csv | 2024-02-11   | No        | 263
    9 : All csv\Examples\ | Table Merge Examples Hobbies 1.csv | 2024-02-11   | No        | 161
   10 : All csv\Examples\ | Table Merge Examples Hobbies 2.csv | 2024-02-11   | No        | 215
   11 : All csv\Examples\ | Table Validate Reference In.csv    | 2024-02-11   | No        | 493
   12 : All csv\Examples\ | Table Validate Target In.csv       | 2024-02-11   | No        | 685
   13 : All csv\Examples\ | Tennis and Golf Players.csv        | 2024-02-11   | No        | 300

Try it yourself: Open LIB_Function_zip_compress.b4p in B4P_Examples.zip. Decompress before use.

See also

zip extract files
zip extract all