FileRecordStream Interface
The Record Stream object (IFileRecordStream) is returned by the CreateRecordFile and OpenRecordFile functions of the ComScript FileObject. Through this object the data in the file can be accessed as complete records with the use of the functions described below.Functions
Name |
Return Type |
Parameters |
Description |
|
Name |
Type |
|||
AddRecord |
Boolean |
RecordData |
String |
Add the records specified in RecordData to the Record Stream. Returns True on success and false on failure. In MaxWaitTimeInSec a maximum wait time can be specified to wait for locks etc. |
MaxWaitTimeInSec |
Integer |
|||
Close |
Boolean |
--- | Closes the current Record Stream file. Returns True when successful |
|
LockRegion |
Boolean |
StartRecord |
Integer64 |
Locks a region of records from the record specified in StartRecord up to and including the record specified in EndRecord. Returns True on success and false on failure. In MaxWaitTimeInSec a maximum wait time can be specified to wait for locks already present on the file or records to lock. |
EndRecord |
Integer64 |
|||
MaxWaitTimeInSec |
Integer |
|||
ReadRecord |
Records in a comma separated String |
NumberOfRecords |
Integer |
Reads the number of records specified in NumberOfRecords from the Record Stream and returns them in a comma separated string. Each next call to this function will start where the previous call left off. In MaxWaitTimeInSec a maximum wait time can be specified to wait for locks etc. |
MaxWaitTimeInSec |
Integer |
|||
ReadRecordAsList | List of Strings | NumberOfRecords | Integer | Reads the number of records specified in NumberOfRecords from the Record Stream and returns them in a list of strings. Each next call to this function will start where the previous call left off. In MaxWaitTimeInSec a maximum wait time can be specified to wait for locks etc. |
MaxWaitTimeInSec | Integer | |||
UnlockRegion |
Boolean |
StartRecord |
Integer64 |
Unlocks the previously locked region from the record specified in StartRecord up to and including the record specified in EndRecord. |
EndRecord |
Integer64 |
Example
PowerShell
#See ComScript Connection Interface
...
$ComScr.Connect()
#Create an object of the FileObject Interface to be able to handle files.
$AmtFile = $ComScr.CreateFileObject()
#Open a file containing records, this creates an object of the FileRecordStream Interface to be able to read & write records.
$RecordsFile = $AmtFile.OpenRecordFile("D:\Files\Data.dat", 1, $false, 50, $false, 5, 0)
#Create a new record file, this creates a second object of the FileRecordStream Interface
$NewRecordsFile = $AmtFile.CreateRecordFile("D:\Files\NewData.dat", 1, $false, 50, $false, $true, 5, 0)
#Read 10 records of the first file and write them to the second file.
$CSVRecords = $RecordsFile.ReadRecord(10, 5)
$RecordsArray = $CSVRecords.Split(",")
ForEach ($Record In $RecordsArray) {
[void]$NewRecordsFile.AddRecord($Record, 5)
}
#Close both record files.
[void]$RecordsFile.Close()
[void]$NewRecordsFile.Close()
# Finally release the variables and clean up the session.
$ComScr.Dispose()