4

How can I write text files using WScript I'm really new on this that's why I cannot give some details. I want to write a log file that can be stored in c://users/user/appdata/local

my sample code, using FileSystemObject

function WriteFile() 
{
   var fso  = new ActiveXObject("Scripting.FileSystemObject"); 
   var fh = fso.CreateTextFile("d:\\Test.txt", true); 
   fh.WriteLine("Some text goes here..."); 
   fh.Close(); 
}

<body onload = "WriteFile();">
</body>

it does return in d: but in local c: it wont.

ziesemer
  • 27,712
  • 8
  • 86
  • 94
Robin Carlo Catacutan
  • 13,249
  • 11
  • 52
  • 85
  • 1
    possible duplicate of [Create and write text file on C hardrive using javascript](http://stackoverflow.com/questions/8461331/create-and-write-text-file-on-c-hardrive-using-javascript) – Brock Adams Dec 11 '11 at 21:42

1 Answers1

7

You are missing one important parameter in fh. The right code is:

var fh = fso.CreateTextFile("d:\\Test.txt", 2, true);

whereas 2 is a bytecode, which tells to fso to write a file. For reading value is 1, and for appending value is 8.

This is clear to you by now, I suppose.

Teemu
  • 22,918
  • 7
  • 53
  • 106