This file contains a procedures to handle files.
MODULE_FILE | 8 |
FILE_EXISTS | 0 |
FILE_OPEN_READ | 1 |
FILE_OPEN_WRITE | 2 |
FILE_READ_NUMBER | 3 |
FILE_READ_STRING | 4 |
FILE_WRITE_NUMBER | 5 |
FILE_WRITE_STRING | 6 |
FILE_CLOSE | 7 |
FILE_DELETE | 8 |
FILE_SIZE | 9 |
Check if a file exists
proc fileExists(string filename)
Name | Type | Description |
---|---|---|
filename | string | The filename. |
Open a file for reading.
proc fileOpenRead(string filename)
Name | Type | Description |
---|---|---|
filename | string | The filename. |
Open a file for writing.
proc fileOpenWrite(string filename)
Name | Type | Description |
---|---|---|
filename | string | The filename. |
Read a number from a file.
proc fileReadNumber(number handle)
Name | Type | Description |
---|---|---|
handle | number | The handle of the file, the file should be opened first with the fileOpen call. |
The simulator contains a `test.rtf` file with the following values:
45, 99, "Hello world", 15
"lib/modules/standard.whl" "lib/modules/file.whl" "lib/modules/screen.whl" proc main() ; Open the file: number handle string filename = "test.rtf" handle = fileOpen(@filename) ; Read two numbers form the opened file... drawNumber(10, 10, fileReadNumber(handle)) drawNumber(10, 30, fileReadNumber(handle)) ; Read a string from the opened file: string s fileReadString(handle, @s) drawText(10, 50, s) ; Read the final number: drawNumber(10, 70, fileReadNumber(handle)) halt() end
Read a string from a file.
proc fileReadString(number handle, string result)
Name | Type | Description |
---|---|---|
handle | number | The handle of the file, the file should be opened first with the fileOpen call. |
result | string | The string which is read from the file. |
Write a number to a file.
proc fileWriteNumber(number handle, number n)
Name | Type | Description |
---|---|---|
handle | number | The handle of the file, the file should be opened first with the fileOpen call. |
n | number | The number to write to the file. |
This demo shows how to write values to a file and read them back.
"lib/modules/standard.whl" "lib/modules/file.whl" "lib/modules/screen.whl" proc main() ; Open the file: number handle string filename = "new.rtf" handle = fileOpen(@filename) ; Write two numbers to the file: fileWriteNumber(handle, 1546) fileWriteNumber(handle, 94) ; Close the file... fileClose(handle) handle = fileOpen(@filename) ; Read two numbers form the opened file... drawNumber(10, 10, fileReadNumber(handle)) drawNumber(10, 30, fileReadNumber(handle)) ; And delete the file... fileDelete(handle) halt() end
Write a string to a file.
proc fileWriteString(number handle, string s)
Name | Type | Description |
---|---|---|
handle | number | The handle of the file, the file should be opened first with the fileOpen call. |
s | string | The string to write to the file. |
This demo shows how to write values to a file and read them back.
"lib/modules/standard.whl" "lib/modules/file.whl" "lib/modules/screen.whl" proc main() ; Open the file: number handle string filename = "new.rtf" handle = fileOpen(@filename) ; Write two numbers to the file: fileWriteNumber(handle, 1546) fileWriteNumber(handle, 94) ; Close the file... fileClose(handle) handle = fileOpen(@filename) ; Read two numbers form the opened file... drawNumber(10, 10, fileReadNumber(handle)) drawNumber(10, 30, fileReadNumber(handle)) ; And delete the file... fileDelete(handle) halt() end
Close a file.
proc fileClose(number handle)
Name | Type | Description |
---|---|---|
handle | number | The handle of the file, the file should be opened first with the fileOpen call. |
Delete a file.
proc fileDelete(string filename)
Name | Type | Description |
---|---|---|
filename | string | The filename to delete. |
Get the size of a file.
proc fileSize(string filename)
Name | Type | Description |
---|---|---|
filename | string | The filename. |