# %creat() function

The %creat() function creates a new
host OS file or prepares to rewrite an existing host OS file designated
by *str* for write only.

## Syntax

```
file.descriptor = %creat(str, mode)
```

## Parameter(s)

| str | Name of the file to create. |
| --- | --- |
| mode | Controls the file mode. Valid values of mode are in the include: mode.h. Combinations of the modes are obtained by adding several elementary modes together. |
Note: On D3, files are closed automatically when the FlashBASIC
program terminates.

## Example(s)

```
include dm,bp,unix.h mode.h
* Create a local file named myfile
* read and write permissions
fd=%creat("myfile",s$iread+s$iwrite)
```
Note the usage of the + operator to
combine flags, where a regular C program would have used an or.

## See also

- [%close() function](https://d3codex.com/pickbasic-flashbasic/percent-close-function/)
- [%fsize() function](https://d3codex.com/pickbasic-flashbasic/percent-fsize-function/)
- [%rdhex() function](https://d3codex.com/pickbasic-flashbasic/percent-rdhex-function/)
- [%read() function](https://d3codex.com/pickbasic-flashbasic/percent-read-function/)
- [%unlink ()function](https://d3codex.com/pickbasic-flashbasic/percent-unlink-function/)
- [%whex() function](https://d3codex.com/pickbasic-flashbasic/percent-whex-function/)
- [%write() function](https://d3codex.com/pickbasic-flashbasic/percent-write-function/)
- [FlashBASIC C functions overview](https://d3codex.com/pickbasic-flashbasic/flashbasic-c-functions-overview/)
- [cfunction statement](https://d3codex.com/pickbasic-flashbasic/cfunction-statement/)

---
Source: https://d3codex.com/pickbasic-flashbasic/percent-creat-function/ - part of the D3Codex reference.
