-2

Possible Duplicate:
how to write a variables's content to a file in JavaScript

I have this piece of code to create a text file. How can I write to this text file?

function makefile() { 

    var fso; 

    var thefile;

    fso = new ActiveXObject("Scripting.FileSystemObject");
    thefile=fso.CreateTextFile("C:\\tmp\\MyFile.txt",true);

    thefile.close()
}
Community
  • 1
  • 1
  • 3
    Dup of [this asked by you](http://stackoverflow.com/questions/6097075/how-to-write-a-variabless-content-to-a-file-in-javascript) – Praveen Lobo May 24 '11 at 06:05
  • This is only a partial duplicate of that question at best; it focuses on using the FSO support. Supposedly this much already creates a file. (There may already be duplicates, the newer tags should help. In any case, if you do opt for a duplicate close -- please *don't pick* the other question as the duplicate :-) –  May 24 '11 at 06:16

2 Answers2

3

Here's one way:

makefile();

function makefile () {

    var fso = new ActiveXObject("Scripting.FileSystemObject"),
        thefile=fso.CreateTextFile("C:\\temp\\MyFile.txt",true);

    thefile.WriteLine('abc');
    thefile.Close();
}
Brett Zamir
  • 14,034
  • 6
  • 54
  • 77
2

Bear in mind this will only work in IE with the correct "relaxed" security permissions.

All the information can be found under FileSystemObject Basics.

When you CreateTextFile (or OpenAsTextStream in write mode) you get a TextStream object back which has a WriteLine method, among others. Please see the examples for "the code".

Happy coding.