> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/zip/extract.md).

# Extract

Extract the source file or folder to the destination folder using the specified format:

\- zip - gzip - tar (raw TAR archive) - tgz/tar.gz (gzip-compressed tar) - bzip/bzip2 (raw bzip2 stream) - tbz/tbz2/tar.bz (bzip2-compressed tar)

The {@code overwrite} argument is used to overwrite the destination file if it already exists, else it will throw an exception. The default is {@code false}.

The {@code recurse} argument is used to extract the files recursively. The default is {@code true}.

The {@code filter} argument is used to filter the files to extract. It can be:

\- A string with a regular expression to match the file names. Example: ".\*\\\\.txt" - A Function/Lambda that receives the file name and returns a boolean. Example: (name) => name.endsWith(".txt")

The {@code entryPaths} argument is used to extract only the files that match the given paths. It can be a string or an array of strings with the paths to extract. Example: "folder1/file1.txt" or \["folder1/file1.txt", "folder2/file2.txt"]

## Method Signature

```
Extract(format=[string], source=[string], destination=[string], overwrite=[boolean], recurse=[boolean], filter=[any], entryPaths=[any])
```

### Arguments

| Argument      | Type      | Required | Description                                                                                  | Default |
| ------------- | --------- | -------- | -------------------------------------------------------------------------------------------- | ------- |
| `format`      | `string`  | `false`  | The format to use for the compression. If omitted, it is detected from the source extension. |         |
| `source`      | `string`  | `true`   | The absolute path to the source file or folder to compress.                                  |         |
| `destination` | `string`  | `true`   | The absolute path with a file name to save as the compressed file. Extension is optional.    |         |
| `overwrite`   | `boolean` | `false`  | Whether to overwrite the destination file if it already exists. Default is false.            | `false` |
| `recurse`     | `boolean` | `false`  | Whether to extract the files recursively. Default is true.                                   | `true`  |
| `filter`      | `any`     | `false`  | A regular expression or a Function/Lambda to filter the files to extract.                    |         |
| `entryPaths`  | `any`     | `false`  | The paths to extract. It can be a string or an array of strings.                             |         |

## Examples

### Extract a zip-file

Extract a zip-file and save the data in the "output-directory".

```java
extract( "zip", "test.zip", "output-directory" );

```

### Extract a multiple zip-files via a directory

Extract all zip-files, which are stored in the "multiple-directory" and save the data in the "output-directory".

```java
extract( "zip", "multiple-directory", "output-directory" );

```

### Additional Examples

```java
extract( "zip", "D:\test.zip", "D:\zipresult" );

```

### Extract a TAR or TGZ archive

Use `tar` for a raw TAR archive and `tgz` for a gzip-compressed TAR archive.

```java
extract( format="tar", source="archive.tar", destination="output-directory" );
extract( format="tgz", source="archive.tgz", destination="output-directory" );
```

When `format` is omitted, it is detected from the source extension. An unrecognized extension requires an explicit `format`.

## Related

* [Compress](/boxlang-language/reference/built-in-functions/zip/compress.md)
* [IsZipFile](/boxlang-language/reference/built-in-functions/zip/iszipfile.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/zip/extract.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
