# INSERT FILE Insert and Compress File into ZIP Archive

> Source: https://manual.pvxplus.com/directives/insert-file

## Format

**INSERT FILE** *filename$* **TO** (*chan* **\[, ERR**=*stmtref*\] **\[,KEY**=*string$***\]**)

***Where:***

|  |  |
| --- | --- |
| *filename$* | Path and filename of the file to compress and add to the ZIP file.<br>Note:  <br>UNIX/Linux does *not* support appending a file to the ZIP archive if the filename contains either a \\ (backslash) or a : (colon). |
| *chan* | Open file channel of the ZIP archive in which to insert the file. |
| *string$* | Path and filename of the added file as recorded in the ZIP archive. (Required only if this is different from *filename$*.) |
| *stmtref* | Program line number or statement label to which to transfer control. |

## Description

The **INSERT FILE** directive will compress a specified file on your system and append it to the end of the ZIP archive.

Note:  
The INSERT FILE directive will not insert a directory, only a file. Attempting to insert a directory will result in an Error #3: Input/Output error on file.  
  
A directory can be inserted using the [WRITE RECORD](https://manual.pvxplus.com/directives/write-record) directive. Any files in sub-directories on your system can be inserted.

*(The INSERT FILE directive was added in PxPlus 2016.)*

## See Also

**[EXTRACT FILE Extract Compressed File from ZIP Archive](https://manual.pvxplus.com/directives/extract-file)**  
**[Accessing ZIP Files](https://manual.pvxplus.com/pxplus-user-guide/file-handling/processing-data-files/accessing-zip-files)**

## Example

```
open (hfn)"test.zip"
insert file "test" to (lfo)
close (lfo)
```
