# filelock statement

The filelock statement sets an exclusive
lock on an entire file.

## Syntax

```
filelock {file.var} {locked statement.block}
```

## Parameter(s)

| file.var | File to lock. If file.var is not specified, then the default file variable is assumed. |
| --- | --- |
| locked statement.block | If the file is already locked (meaning another user has a file or an item lock, or is currently updating that file) and the optional locked clause is present, then statement.block is executed. If no locked clause is present, then the statement blocks until the situation is resolved.Note: system(0) in the locked clause returns the port number that has the item locked. |

## Description

The filelock statement is useful for preventing updates to a file while a sequential
operation is running (like a BASIC select).

Note: **For Windows:** The filelock statement
is supported only for VME files. It is not supported for FSI files.

Once a file lock has been set, any attempt by another port to
update, item lock, or file lock that file fails.

File locks
are displayed by the TCL list-locks command as
special item locks with item-IDs of * and hash
values of 0. If necessary, these locks can be cleared atypically with
the TCL unlock-file command.

CAUTION: The filelock statement sets broad locks that
can severely impact other users. Developers should plan carefully
when using this facility.

## See also

- [begin work statement](https://d3codex.com/pickbasic-flashbasic/begin-work-statement/)
- [clear-basic-locks macro](https://d3codex.com/tcl/clear-basic-locks-macro/)
- [clear-locks command](https://d3codex.com/tcl/clear-locks-command/)
- [fileunlock statement](https://d3codex.com/pickbasic-flashbasic/fileunlock-statement/)
- [list-locks command](https://d3codex.com/tcl/list-locks-command/)
- [statement blocks](https://d3codex.com/pickbasic-flashbasic/statement-blocks/)
- [Statements and functions](https://d3codex.com/pickbasic-flashbasic/statements-and-functions/)
- [then clause](https://d3codex.com/pickbasic-flashbasic/then-clause/)
- [then/else statement blocks](https://d3codex.com/pickbasic-flashbasic/then-else-statement-blocks/)
- [u0191 user exit](https://d3codex.com/proc/u0191-user-exit/)
- [u1191 user exit](https://d3codex.com/proc/u1191-user-exit/)
- [u2191 user exit](https://d3codex.com/proc/u2191-user-exit/)
- [u3191 user exit](https://d3codex.com/proc/u3191-user-exit/)
- [unlock statement](https://d3codex.com/pickbasic-flashbasic/unlock-statement/)
- [unlock-file command](https://d3codex.com/tcl/unlock-file-command/)
- [unlock-item command](https://d3codex.com/tcl/unlock-item-command/)

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