zip()

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

Description:
Perform zip operations.

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

Note:

The external library function (See External Library Guide) performs  operations on a compressed file of zip format.

Option:

@u

Decompress a file.

@a

Append files to an existing compressed folder.

@d

Delete specified files from a compressed folder.

@n

 Only handle files in directories on the current level, without performing the operation on subdirectories.

@f

List file names in a compressed file.

@p

List directory names in a compressed file.

Parameter:

zipfile

A compressed file or a file object.

encoding

Character set, which is UTF-8 by default.

password

A password; can be absent.

path

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

To compress a file, “,” after this parameter should be retained when it is absent and parameter files is present;

To decompress a file, this parameter represents the path to which the decompressed file is exported. When it is absent, export the decompressed files to the path where the zip file is located. If path is a relative path, append decompressed files to the path containing the zip file; if it is an absolute path, export the compressed files to a specified directory;

To delete the zip file, path represents the folder starting from the root directory where the zip file is located.

files

A file or a sequence of files. You can use wildcard characters * and ? in file names to represent any string and a single character respectively. When a wild card is used and when the name of file folder to be compressed is inconsistent with that of the to-be-generated folder, compress the files along with the folder accommodating them, that is, compress the folder with the absolute path. In that case, the directory name list generated via @p option is empty.

Return value:

Boolean/Sequence

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.