# ucreate command

The ucreate command creates and opens a specified file on the host
 system.

## Format

```
UCREATE <path> TO FileHandle THEN statement(s) ELSE statement(s)
```

## Parameters

| path | File expressed by the valid path name, within quotes. |
| --- | --- |
| FileHandle | Contains the file descriptor of the file that is open for write only. |

## Description

If the file already exists, the ucreate command shortens the length of the
 file to 0. If the file does not exist, the ucreate command creates a new
 file. The file pointer is positioned at the beginning of the file. All future references to this
 file must be made through *FileHandle*. If an error occurs, the ELSE path
 executes.

## Example(s)

The following example creates the \books\chap1.txt file. If the file
 exists, the ucreate command truncates the file to zero bytes. The file opens
 for reading/writing and the file descriptor is returned in the variable FILEDES. If an error
 occurs, the ELSE clause executes:

```
FILENAME="c:\books\chap1.txt"
UCREATE FILENAME TO FILEDES ELSE
 PRINT "Unable to create and open ":FILENAME
 STOP
END
UCLOSE FILEDES ELSE STOP
```

## See also

- [O/S interoperability commands and functions](https://d3codex.com/pickbasic-flashbasic/os-interoperability-commands/)
- [uclose command](https://d3codex.com/pickbasic-flashbasic/uclose-command/)
- [udelete command](https://d3codex.com/pickbasic-flashbasic/udelete-command/)
- [uerror() function](https://d3codex.com/pickbasic-flashbasic/uerror-function/)
- [uexecute command](https://d3codex.com/pickbasic-flashbasic/uexecute-command/)
- [ulock command](https://d3codex.com/pickbasic-flashbasic/ulock-command/)
- [ulseek() function](https://d3codex.com/pickbasic-flashbasic/ulseek-function/)
- [umessage command](https://d3codex.com/pickbasic-flashbasic/umessage-command/)
- [uopen command](https://d3codex.com/pickbasic-flashbasic/uopen-command/)
- [uread command](https://d3codex.com/pickbasic-flashbasic/uread-command/)
- [ureadline() function](https://d3codex.com/pickbasic-flashbasic/ureadline-function/)
- [usystem() function](https://d3codex.com/pickbasic-flashbasic/usystem-function/)
- [uwaitfor command](https://d3codex.com/pickbasic-flashbasic/uwaitfor-command/)
- [uwrite command](https://d3codex.com/pickbasic-flashbasic/uwrite-command/)

---
Source: https://d3codex.com/pickbasic-flashbasic/ucreate-command/ - part of the D3Codex reference.
