This document describes the public methods and usage examples for the FileIO Parent Script.
Summary of Public Methods
Details of Public Methods
new() |
| Syntax | | new (object, string filename, symbol accessMode)
|
| Returns | | object instance |
| Description | | Creates a new instance of the script and assigns it to the specified file. The specified is opened with the given accessMode. | Argument | | Description | | filename | | This should contain the full path and filename to open and/or create. | | accessMode | | Must be one of #read, #write or #append #read Opens the file for read-only operations. #write Creates a new file for read and write operations. If the specified filename already exists, it will be deleted. #append Opens an existing file for read and write operations. If the specified filename already exists, the file pointer is automatically set to the end of the file. If the specified filename does not exist, a new file is created. | |
| Example | | This will open the file "c:\file.txt" for read-only operations. |
oFile = new(script "FileIO Parent", "c:\file.txt", #read) |
_Kill() |
| Syntax | | _Kill (object) |
| Returns | | void |
| Description | | Closes the file and removes all references to the FileIO Xtra. This is the proper method of completing your file operation. |
| Example | | This example demonstrates how to close your file when you have completed operations. oFileObject._Kill() oFileObject = void |
_ReadLine() |
| Syntax | | _ReadLine (object, [ symbol readMode ]) |
| Returns | | string |
| Description | | Reads one line from the open file, from the current position of the file pointer within the file. The optional argument readMode can trim CR/LF characters from the string. | Argument | | Description | | readMode | | If readMode = #stripcr, then all carriage return (CR) and line feed (LF) characters will be removed from the beginning and end of the read string. By default, CR/LF characters are NOT removed from the string. | |
| Example | | Read a line from the current file and assign it to the variable myLine. myLine = oFileIn._ReadLine() Read a line from the current file, and trim all CR/LF characters. myLine = oFileIn._ReadLine(#stripcr) |
_WriteLine() |
| Syntax | | _WriteLine (object, string stringToWrite, [ symbol lineMode ])
|
| Returns | | void |
| Description | | Write the given string to the current file. The optional argument lineMode can append the appropriate CR/LF characters to the string. The correct CR/LF characters are chosen based on the determined platform. Optionally, they can be defined using the _DefineTerminator() function. | Argument | | Description | | lineMode | | If lineMode = #addcr, then the appropriate CR/LF characters will be appended to the line. By default, CR/LF characters are NOT appended. | |
| Example | | Write a string to the current file. oFileOut._WriteLine(myString) Write a string to the current file and append the CR/LF characters. oFileOut._WriteLine(myString, #addcr) |
_DefineTerminator() |
| Syntax | | _DefineTerminator (object, symbol type)
|
| Returns | | void |
| Description | | Specifically define the line terminator character(s) regardless of the current operating system. When the FileIO Parent Script is first instantiated, it checks the operating system and assigns a default terminator character as follows: Windows - CR + LF (ascii 13 + ascii 10) Macintosh - CR (ascii 13) | Argument | | Description | | type | | Can be one of #win, #mac or #unix #win defines the terminator as CR + LF
#mac defines the terminator as CR
#unix defines the terminator as LF | |
| Example | | Set the terminator string for a Windows operating system. oFileOut._DefineTerminator(#win) |
_IsPastEOF() |
| Syntax | | _IsPastEOF (object) |
| Returns | | boolean |
| Description | | Checks whether the file pointer is at the end of the file. If we have read to the end of the file, _IsPastEOF returns TRUE. Otherwise we return FALSE. |
| Example | | Read all lines in a file and exit the repeat loop when we have reached the end of the file. lLines = []
repeat while (NOT oFileIn._IsPastEOF()) lLines.add(oFileIn._ReadLine(#stripcr)) end repeat |
_SetPosition() |
| Syntax | | _SetPosition (object, integer position) |
| Returns | | void |
| Description | | This method duplicates the setPosition method inside the FileIO Xtra and is simply provided as a wrapper within the context of the FileIO Parent script. This wrapper provides no extra functionality. Position the file pointer at a specific location inside the file. Future reads/writes will occur at this position. | Argument | | Description | | position | | This is the byte offset at which to position the file pointer. | |
| Example | | Set the file pointer ahead 1024 bytes from the beginning of the file. oFileIn._SetPosition(1024) Move the file pointer ahead 100 bytes from the current position. oFileIn._SetPosition(oFileIn._GetPosition() + 100) Move the file pointer to the end of the file. oFileIn._SetPosition(oFileIn._GetLength()) |
_GetPosition() |
| Syntax | | _GetPosition (object) |
| Returns | | integer |
| Description | | This method duplicates the setPosition method inside the FileIO Xtra and is simply provided as a wrapper within the context of the FileIO Parent script. This wrapper provides no extra functionality. Get the current location of the file pointer inside the file. |
| Example | | Determine the current location of the file pointer. dPos = oFileIn._GetPosition() |
_GetLength() |
| Syntax | | _GetLength (object) |
| Returns | | integer |
| Description | | This method duplicates the setPosition method inside the FileIO Xtra and is simply provided as a wrapper within the context of the FileIO Parent script. This wrapper provides no extra functionality. Get the length (bytes) of the current file. |
| Example | | Determine the length of the current file. dFileLength = oFileIn._GetLength() |