-4

I am trying to create and edit a text file usinf Javascript.

I have used the following code. But it returns an error.

SyntaxError: missing ; before statement

var fso = CreateObject("Scripting.FileSystemObject");
var s = fso.CreateTextFile("I:\Satheesh\test.txt", True);
s.writeline("HI");
s.close

Please note that my Javascript should run only on firefox.

Thanks in Advance

9
  • 1
    Don't you think it should be s.Close(); ?? Commented Apr 28, 2014 at 9:34
  • 3
    You are taking an example in VBScript that relies on a proprietary Microsoft API using ActiveX if you used the JScript example (msdn.microsoft.com/en-us/library/2z9ffy99(v=vs.84).aspx). This will not work. Commented Apr 28, 2014 at 9:34
  • @Log1c of course it is s.close Commented Apr 28, 2014 at 9:40
  • @TheShellfishMeme the example you provided works only for Internet Explorer Commented Apr 28, 2014 at 9:40
  • @BenjaminGruenbaum see now Commented Apr 28, 2014 at 9:41

1 Answer 1

0

I see that you've edited the question.

The original error you were getting:

SyntaxError: missing ; before statement

Is caused by the "set" before the first variable name:

set fso = CreateObject("Scripting.FileSystemObject");

Which is not valid Javascript. You've (correctly) changed "set" to "var".

var fso = CreateObject("Scripting.FileSystemObject");

So I expect that error message has now gone away - in which case your original question is answered.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.