d

File IO Basics

Working with files is one of the fundamental tasks programmers need to learn.

Javascript did not include much in the way of handling files natively, so we must use a COM object Microsoft included with WSH.

Scripting.FileSystemObject

var fso = new ActiveXObject( "Scripting.FileSystemObject" );

Scripting.FileSystemObject exposes a number of methods and properties for interacting
with files/folders and their attributes.

With it we can create, read, write, append, move, copy, and delete files. It also
lets us work with Folders as well.

Open File

Create File


var fso = new ActiveXObject( "Scripting.FileSystemObject" );

var f = fso.OpenTextFile( "myfile.txt", 8 );

Open File

Write File

Read File