# close statement

The *close* statement closes the file
identified by *file.var*. If *file.var* is not specified, the file referenced by the default *file.var* is closed.

## Syntax

```
close {file.var}
```

## Parameter(s)

| file.var | Specifies the file to be closed.Warning: For Windows: Copying file variables can be dangerous since a subsequent close on any of the file variables will close the file. Thus, any remaining file variables (containing a copy of the now invalid file handle) may be incorrectly allocated to the wrong file. |
| --- | --- |
| root.var | Specifies to close the parent file of an index that was opened using the root statement. |

## Description

If used when the TCL set-remote-close command is set to on, the close statement also closes any associated remote files and releases any
resources allocated to open files (such as memory and handles).

This statement must be used if a file is opened and then a delete-file is executed with an execute statement.

Files close by default when a program ends.

CAUTION:

- A file should be closed before it is deleted.

- The close statement is not supported for files within transactions.

- If set-remote-close is set to on, item locks and file locks associated with that file handle are released.

## Example(s)

```
open ’testfile’ to testfile then
close testfile
execute ’delete-file testfile’
end
execute ’create-file testfile ’:newdictmod:’ ’:newdatamod
```

## See also

- [delete-file command](https://d3codex.com/tcl/delete-file-command/)
- [File control block](https://d3codex.com/definitions/file-control-block/)
- [File variable](https://d3codex.com/pickbasic-flashbasic/file-variable/)
- [open statement](https://d3codex.com/pickbasic-flashbasic/open-statement/)
- [Statements and functions](https://d3codex.com/pickbasic-flashbasic/statements-and-functions/)

---
Source: https://d3codex.com/pickbasic-flashbasic/close-statement/ - part of the D3Codex reference.
