File System Object

<% @ Language="JavaScript" %>

<HTML>
<
HEAD><TITLE>JavaScript Mailing List</TITLE></HEAD>

<BODY>

<%

var fsObj, eList;
var ForAppending = 8;

/*
create a new instance of the FSO - File System Object, same idea we use for
var someArrayVar = new Array();
var someDateVar = new Date(); or
var someImageVar = new Image();
*/

// Create the FileSystemObject which is an ActiveX Object
var fsObj = new ActiveXObject("Scripting.FileSystemObject");

var eList = fsObj.OpenTextFile("c:\lists\js.txt", ForAppending, true, false);

// Write the email address to the text file
eList.WriteLine(Request("emailAddr"));

// Close the TextStream Object
eList.Close();

%>

<H3>You have been successfully added to the JavaScript Mailing List.</H3>

<A HREF="../default.htm">Back to the JavaScript Home Page</A>

</BODY>
</
HTML>

In this example we create an instance of the FSO. Once an instance of the FSO exists we can us the Object to Open js.txt so that we append information to the file. After we have appended the information to file we close and destroy the Object.

NOTE: Once you have finished with an Object, you should Close() it and free any associated system resources. NOTE: This doesn't actually remove the object from memory; so you can Open() it again if you need to. To completely free the memory for the object you should set it to null.