Description
Extracts the compressed archive or data stream.
Applies to
ExtractorObject objects
Syntax 1: Extracts the compressed archive
objectname.Extract ( string source, string target )
Syntax 2: Extracts the specified files (or folders) from the specified package
objectname.Extract ( string source, string items[], string target )
Syntax 3: Extracts the specified file from the compressed package into a blob
objectname.Extract ( string source, string item, ref blob target )
Syntax 4: Extracts the compressed blob data
objectname.Extract ( blob source, ref blob target {, ArchiveFormat format })
Argument |
Description |
---|---|
objectname |
The name of the ExtractorObject object. |
source |
A string whose value is the full directory of the compressed archive. Or a blob whose value is the compressed data stream. |
items[] |
The specified files (or folders) to extract. The files (or folders) can be obtained through GetFilesList. If you specify a single file in a subfolder, the method will create the whole folder structure to the file on target. |
item |
The specified file to extract. You can only extract one file (cannot be multiple files or a folder) into a blob. |
target |
A string whose value is the directory where the compressed archive will be extracted. The existing files with the same name on target will be overwritten. Or a blob where the decompression results will be stored. |
format (optional) |
A value of the enumerated datatype ArchiveFormat specifying the format of the source file. Values are:
|
Usage
The Extract method determines the archive format according to the file extension; therefore, if the file extension has been changed manually (for example, from .rar to .zip), the Extract method will fail to extract the file and will return the error code -10.
When extracting to a blob data, you can only extract one file (rather than a folder or multiple files) into a blob.
Return value
Integer.
Returns the following value. If any argument's value is null, the method returns null.
1 -- Success
-1 -- A general error occurred.
-2 -- The password entered is illegal.
-3 -- The operation is not supported for the source file format.
-4 -- The task thread is aborted.
-5 -- A task thread is currently running.
-6 -- No password is entered. You must enter the password.
-7 -- The password is incorrect.
-8 -- Failed to get new memory when saving the decompressed file.
-9 -- Failed to read the compressed file.
-10 -- Unrecognized format or the encrypted file name option is used when compressing the document.
-11 -- Access denied when extracting the archive.
-12 -- The compressed file does not exist.
-13 -- The directory where the decompressed file will be saved does not exist.
-14 -- Failed to extract the compressed file.
-15 -- The file to be decompressed is not in the package.
-16 -- The current operation does not support the folder decompression.
Example 1
This example demonstrates how to extract a compressed package.
ExtractorObject lnv_extractor Integer li_return string ls_source, ls_target ls_source = "D:\testcom.7Z" ls_target = "D:\testextract" lnv_extractor = Create ExtractorObject li_return = lnv_extractor.extract (ls_source, ls_target)
Example 2
This example demonstrates how to compress and extract a blob data.
CompressorObject lnv_compress ExtractorObject lnv_extractor Integer li_return blob lb_source, lb_target, lb_extract lb_source = blob ("A123456") lnv_compress = create CompressorObject lnv_extractor = create ExtractorObject li_return = lnv_compress.Compress (lb_source, lb_target, ArchiveFormat7Zip!) if li_return = 1 then li_return = lnv_extractor.extract (lb_target, lb_extract, ArchiveFormat7Zip!) end if
Example 3
This example extracts two files (test1.txt, test2.txt) and a folder (test_folder) from the package.
ExtractorObject lnv_extractor string ls_source, ls_password, ls_extractfiles[], ls_target long ll_return lnv_extractor = create ExtractorObject ls_source = "E:\Test.rar" ls_extractfiles[1] = "test1.txt" ls_extractfiles[2] = "test2.txt" //Suppose a folder is specified to be extracted, then all //of the files contained in this folder will be extracted. ls_extractfiles[3] = "test_folder" ls_target = "E:\" //Suppose the package requires a password lnv_extractor.Password = ls_password ll_return = lnv_extractor.extract (ls_source, ls_extractfiles, ls_target)
Example 4
This example extracts test1.txt from the package into a blob data. You can only extract one file (not a folder or multiple files) into a blob.
ExtractorObject lnv_extractor string ls_source, ls_password, ls_extractfile long ll_return blob blb_target lnv_extractor = create ExtractorObject ls_source = "E:\Test.rar" ls_extractfile = "test1.txt" //Suppose the package requires a password lnv_extractor.Password = ls_password //Extract one file (cannot be multiple files or a folder) into a blob ll_return = lnv_extractor.extract (ls_source, ls_extractfile, blb_target)
See also