# ulseek() function

The ulseek() function moves the file pointer in an open file and
 returns the position of the file pointer, which is the number of bytes from the beginning of the
 file.

## Format

```
ULSEEK(FileHandle, n,{0|1|2})
```

## Description

The ulseek() function positions the file pointer in
 *FileHandle*
 *n* bytes from either the beginning, current, or ending position in the file.

 The offset (*n*) can have a positive, negative, or zero value:

- Use a negative offset to move the file pointer backwards (towards the beginning of the file).

- Use an offset of zero to position the pointer at the exact beginning or the exact end of the file, or to read its position without moving it.

 To indicate where the offset should start, specify one of the following as the second
 parameter:

| 0 | The position of the file pointer is at the beginning of the file. |
| --- | --- |
| 1 | Present position of the file pointer. |
| 2 | The position of the file pointer is at the end of the file. |

 The value returned is the absolute location of the file pointer from the beginning of the
 file, measured in bytes. If an error occurs, a value of -1 is returned.

## Example(s)

| ULSEEK (FileHandle, 0, 2) | Points to the end of a file. |
| --- | --- |
| ULSEEK (FileHandle, 0, 0) | Points to the beginning of a file. |
| ULSEEK (FileHandle, -8, 2) | Points to the eighth byte before the end of the file. |
| ULSEEK (FileHandle, 0, 1) | Returns the current file pointer position. |

 The following example opens the \books\chap3.txt file for reading and
 reads the last 50 bytes of the file into the variable *VAR2*. If it is unable
 to do this, it prints an error message telling which inter-operating system command failed
 (ulseek or uread).

```
FILENAME="c:\books\chap3.txt"
UOPEN FILENAME FOR READ TO FILEDES ELSE
 PRINT "Unable to open ":FILENAME
 STOP
END
* Use ULSEEK to move pointer 50 bytes in
* from end of file
VAR1=ULSEEK(FILEDES,-50,2)
IF (VAR1<>-1) THEN
 * Now move read last 50 bytes
 UREAD VAR2 FROM FILEDES FOR 50 ELSE
 PRINT "Unable to read ":FILENAME
 GOTO EOJ:
 END
END ELSE
 PRINT "Ulseek failed on file ":FILENAME
 GOTO EOJ:
END
```

## 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/)
- [ucreate command](https://d3codex.com/pickbasic-flashbasic/ucreate-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/)
- [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/ulseek-function/ - part of the D3Codex reference.
