Is it possible to write a file to disk using JScript?

Yes, you can write text files using ActiveXObjects, such as in the following example:


var fso = new ActiveXObject("Scripting.FileSystemObject");
var dir = DS.Script.GetProjectDirectory();

// user can modify the next few lines to suit needs
var filename = "some_file.txt";

var forReading = 1, forWriting = 2, forAppending = 8;
var create = true; // if file doesn't exist, then create it
var file = fso.CreateTextFile(dir + "" + filename, forWriting, create);

var someLineOfData = "some line of data";

// or, if you already have the newline characters (system dependent)

var someData = "line 1rn";
someData += "line 2rn";
someData += "line 3rn";



WBScript.Out("Data written to " + dir + "" + filename, true, "Complete");

Show Form
No comments yet. Be the first to add a comment!