Overview
Sometimes using Rapise you need to access files on the Windows filesystem, either for testing purposes, or to object test data stored in a flat CSV, TSV or text file. This sample illustrates how you can access the File System using Rapise and the Windows FileSystemObject (http://msdn.microsoft.com/en-us/library/aa242706(v=vs.60).aspx).
Code Sample
The following sample code illustrates how to access files using Rapise:
function Test()
{
//IOMode constants
var IOMode_ForReading = 1;
var IOMode_ForWriting = 2;
var IOMode_ForAppending = 8;
//var Format constants
var IOFormat_ASCII = 0;
var IOFormat_Unicode = -1;
//This sample demonstrates how to manipulate the Windows file system using Rapise
//We shall open a text file for writing in this simple example
var fso = new ActiveXObject('Scripting.FileSystemObject');
var ts = fso.CreateTextFile('C:\\Temp\\MyTestFile.txt');
ts.Close();
var file = fso.GetFile('C:\\Temp\\MyTestFile.txt');
ts = file.OpenAsTextStream(IOMode_ForWriting, IOFormat_Unicode);
ts.WriteLine('Hello World!');
ts.Close();
Tester.Message('Wrote File');
//Now read this file back
file = fso.GetFile('C:\\Temp\\MyTestFile.txt');
ts = file.OpenAsTextStream(IOMode_ForReading, IOFormat_Unicode);
var text = ts.ReadLine();
Tester.Message(text);
ts.Close();
}