zip()

Read(1886) Label: zip, compression, decompression,

Description:
Perform file compression operations.

Syntax:
zip(
zipfile:encoding,passowrd; path, files)

Note:

The external library function (See External Library Guide) performs various file compression operations.

Option:

@u

Decompression.

@a

Append a new directory to an existing compressed file.

@d

Delete a file in a compressed file.

@n

Won’t perform recursive compression over subdirectories, only compress files of the current level.

@f

List files in a compressed file.

@p

List directories in a compressed file.

Parameter:

zipfile

A compressed file or a file object.

encoding

Charset; default is utf-8.

password

A password; can be absent.

path

The root directory holding a to-be-compressed file; it is the directory holding zipfile when the parameter is null or absent.

With compression, the comma (“,”) after this parameter should be retained when it is absent and parameter files is present;

With decompression, this parameter specifies the path along which the decompressed file is output. If it is absent, output the decompressed to the path where the zip file is located. If parameter path is a relative path, append it to the path containing the zip file; if it is an absolute path, output the compressed file to the specified directory;

When deleting the zip file, this parameter represents the folder beginning form the root path where the zip file is saved.

files

A file or a sequence of files. Wildcard characters * and ? are allowed in a file name; the former represents any string and the latter represents a single character. With wildcard characters and if the name of the directory where the to-be-compressed file(s) are located isn’t the same with that of the directory holding the future compressed file(s), then the function will also compressed the directory, which contains the absolute path. In that case, the directory list generated via @p option is empty.

Return value:

Boolean value for compression, appending or deletion, or a file list for other operations

Example:

 

A

 

1

=zip("D:/z1.zip":"GBK","123";"D:/testData/f1","D:/testData/f1/*.xls")

 

2

=zip("D:/z1.zip":"GBK";,"D:/testData/f1")

 

3

=zip(file("D:/z1.zip");,"D:/testData/f1")

Compress all files under D:/testData/f1/ directory into z1.zip as parameter zipfile is a file object.

4

=zip("D:/z4.zip";"D:/testData/f1","/*")

Compress all files under D:/testData/f1/ directory into z4.zip.

5

=zip("D:/z5.zip";"D:/testData/f1")

Compress all files under D:/testData/f1/ directory into z5.zip.

6

=zip("D:/z6.zip";,"D:/testData/f1/?ity.txt")

Compress files under D:/testData/f1/ directory whose names matching ?ity.txt with wildcard character ? into z6.zip.

7

=["f2/*.txt","f2/*.csv","f2/*.xls"]

 

8

=zip("D:/z8.zip";"D:/testData",A7)

Parameter files is a sequence, so compress text, csv and xls files under D:/testData/f2/ directory into z8.zip.

9

=[file("*.xlsx"),file("*.txt"),file("*.json")]

 

10

=zip("D:/z9.zip";"D:/testData",A9)

Parameter files is a sequence of file objects, so compress xlsx, txt, and json files under D:/testData directory into z9.zip.

11

=zip("D:/ZipTest/z11.zip";"testData/f1")

Parameter path is a relative path, which is relative to the path parameter zipfile specifies; this compresses files under D:/ZipTest/testData/f1/into z11.zip.

12

=zip@u("D:/z1.zip","123";"D:/zfu/z1")

Decompress z1.zip into D:/zfu/z1 directory with password 123.

13

=zip@u("D:/z1.zip","123")

Decompress z1.zip into D:/ directory with password 123.

14

=zip@a("D:/z2.zip";,"D:/testData/f_a/")

Append files under D:/testData/f_a/ directory to z2.zip

15

=zip@a("D:/z2.zip";,"D:/testData/f_a","*.txt")

Append all txt files, including those in the subdirectories under f_a directory under D:/testData/f_a/ directory to z2.zip.

16

=zip@an("D:/z2.zip";,"D:/testData/f_a","*.txt")

Append all txt files, not including those in the subdirectories under f_a directory under D:/testData/f_a/ directory to z2.zip.

17

=zip@d("D:/z2.zip";"/","C*.txt")

Delete files whose names match C*.txt from z2.zip

18

=zip@d("D:/z2.zip";"/",["*.txt","*.xls","*.csv"])

Delete all txt, xls and csv file from z2.zip.

19

=zip@n("D:/z13.zip";,"D:/testData/")

Compress files under D:/testData/ into z13.zip; with @n option, the function doesn’t perform a recursion on subdirectories, which means files under subdirectories won’t be compressed.

20

=zip@f("D:/z1.zip")

List files under a compressed file without a password.

21

=zip@f("D:/z2.zip";"zdata",["*.txt","*.xls"])

List all txt and xls files under zdata directory in the compressed file and display them beginning from the root directory.

22

=zip@p("D:/z2.zip")

List directories in a compressed file.

23

=zip@p("D:/z14.zip")

List multilevel directories.