6 accessing a file – Casio Naurtech CETerm Ver.5.5 Scripting Guide User Manual

Page 110

Advertising
background image

N

AURTECH

W

EB

B

ROWSER AND

T

ERMINAL

E

MULATION FOR

W

INDOWS

CE

AND

W

INDOWS

M

OBILE




CETerm Scripting Guide

Page 110


{
// Resume online inventory, and save cached
// data to file in background.
CETerm.SetTimeout( "BackgroundSave(" + session + ");", 10 );
}
}

/* BackgroundSave */
function BackgroundSave( session )
{
var d = new ActiveXObject( "Microsoft.XMLDOM" );
d.loadXML(
"<?xml version=\"1.0\"?><Books>" +
"<Book QTY=\"10\"><Title>Beginning XML</Title></Book>" +
"<Book QTY=\"2\"><Title>Mastering XML</Title></Book>" +
"</Books>");

if (!OS.File.Write( "\\FlashDisk\\inventory.xml", d.xml ))
{
OS.Alert( "Failed to save inventory." );
}
}


5.6

A

CCESSING A

F

ILE

The File automation object provides basic access to the Windows CE filesystem.
It supports whole-file read and write, but does not support the concept of an
“open” file with piecewise read or write. You can also create and delete file
directories.

This example shows how to append to an existing file by using a combination of
read and write. The new File.Append() method should now be used to append
data to files but this example still illustrate how to use the File object.

/* AppendToFile */
function AppendToFile( filename, addedContent )
{
var status = false;
var F = OS.File;

// Check if file exists
var attributes = F.GetAttributes( filename );
if (attributes != 0xFFFFFFFF)
{
var content = F.Read( filename );
status = F.Write( filename, content + addedContent );
}
else

Advertising
This manual is related to the following products: