Description:
Perform tar operations.
Syntax:
gzip(tarfile:encoding; path, files)
Note:
External library function (See External Library Guide).
The function performs tar operations on a compressed file of tar.gz 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:
tarfile |
A compressed file or file object. |
encoding |
Character set, which is UTF-8 by default. |
path |
The root directory where the file to be compressed is located. When the parameter is absent or its value is null, the directory is that where tarfile is located. To perform a compression, “,” after this parameter cannot be omitted when path is absent while parameter files is present. path represents the path to which the decompressed file is exported. When it is absent, the decompressed file will be exported to the path where zipfile is located; when path is a relative path, append the compressed file to path tarfile; and when path is an absolute path, export the compressed file to a specified location. To delete compressed files, path represents a folder in the compressed folder starting from the root directory. |
files |
A file or a sequence of files. You can use wild cards * 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 |
=gzip("F:/tmp/test/g1.tar.gz":"GBK";"F:/tmp","F:/tmp/*.txt") |
Compress all txt files in F:/tmp to F:/tmp/test/g1.tar.gz; character set is GBK. |
2 |
=gzip("F:/tmp/test/g2.tar.gz":"GBK";,"F:/tmp/f1") |
Compress all files in F:/tmp/f1 to g2.tar.gz. character set is GBK. As parameter path is absent, placeholder “,” should not be omitted. |
3 |
=gzip(file("F:/tmp/test/g3.tar.gz");,"F:/tmp/f1") |
As parameter tarfile is a file object, compress all files in F:/tmp/f1 to g3.tar.gz. |
4 |
=gzip("F:/tmp/test/g4.tar.gz";"F:/tmp/f2","*") |
Compress all files in F:/tmp/f2 to g4.tar.gz. |
5 |
=gzip("F:/tmp/test/g4.tar.gz";"F:/tmp/f2") |
Same as above. |
6 |
=gzip("F:/tmp/test/g5.tar.gz";,"F:/tmp/f2/?ity.txt") |
Compress files matching ?ity.txt in F:/tmp/f2 to g5.tar.gz. |
7 |
=["f2/*.txt","f2/*.csv","f2/*.xls"] |
|
8 |
=gzip("F:/tmp/test/g6.tar.gz";"F:/tmp",A7) |
Compress txt, csv and xls files in F:/tmp/f2 to g6.tar.gz. |
9 |
=[file("*.xlsx"),file("*.txt"),file("*.json")] |
|
10 |
=gzip("F:/tmp/test/g7.tar.gz";"F:/tmp/f1",A9) |
Compress xlsx, txt, and Json files in F:/tmp/f1 to g7.tar.gz. |
11 |
=gzip("F:/tmp/test/g8.tar.gz";"f3") |
Compress files in F:/tmp/test/f3 to g8.tar.gz. |
12 |
=gzip@u("F:/tmp/test/g9.tar.gz";"F:/tmp/f1") |
Decompress file g9.tar.gz to F:/tmp/f1. |
13 |
=gzip@u("F:/tmp/test/g9.tar.gz") |
Decompress file g9.tar.gz to F:/tmp/test. |
14 |
=gzip@a("F:/tmp/test/g10.tar.gz";"F:/tmp/f1","*.txt") |
Append txt files in F:/tmp/f1 to g10.tar.gz. |
15 |
=gzip@dn("g11.tar.gz";,["*.txt","*.xls","*.csv"]) |
Delete all the txt, xls and csv files in g11.tar.gz, but do not perform the same operation on subdirectories. |
16 |
=gzip@f("g12.tar.gz") |
List all file names in g12.tar.gz. |
17 |
=gzip@p("g13.tar.gz") |
List all folders in g13.tar.gz. |