Shoutbox

Writing files? - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Writing files? (/showthread.php?tid=94624)

Writing files? by ultimatebuster on 05-21-2010 at 02:46 AM

I'm relatively new to JavaScript & JScript. Recently familiarized myself with the language.

Since I program in python before, I got some questions about writing files.

If there an API to write files to the HDD somewhere? A plain text file?

All I want to do is store a Date() whenever I click a menu button from a chat window. This Date() is associated with the Contact, so that whenever I click another menu button, it pulls up the time.

I'm doing this to futhur familiarize myself with the language.

Thanks for any help


RE: Writing files? by Chris4 on 05-21-2010 at 03:22 AM

Are you looking for the Scripting Documentation?

You write new scripts by going to Plus! > Preferences > Scripts > Create New.

Hope that helps.


RE: Writing files? by matty on 05-21-2010 at 10:24 AM

Check a look at MSDN for Scripting.FileSystemObject. It has functions called CreateTextFile and WriteFile and Read file etc.


RE: Writing files? by ultimatebuster on 05-21-2010 at 08:50 PM

I looked at it, but I can't seems to write a file

code:
    var ForAppending = 8;

    var fso, theFile;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    theFile = fso.OpenTextFile("data.txt", ForAppending, true);
    theFile.WriteLine("Hello World!");
    theFile.Close();

RE: Writing files? by n3mo on 05-31-2010 at 07:35 PM

You probably dont have permission to create the file in that directory. Try this:

code:
theFile = fso.OpenTextFile(MsgPlus.ScriptFilesPath  + "/data.txt", ForAppending, true);

The MsgPlus:: ScriptFilesPath property returns the full path to the current script's files.
RE: Writing files? by matty on 05-31-2010 at 08:08 PM

quote:
Originally posted by n3mo
Javascript code:
theFile = fso.OpenTextFile(MsgPlus.ScriptFilesPath  + "/data.txt", ForAppending, true);



That is wrong...
Javascript code:
theFile = fso.OpenTextFile(MsgPlus.ScriptFilesPath  + "\\data.txt", ForAppending, true);


RE: Writing files? by Matti on 06-01-2010 at 03:58 PM

Also, JScript doesn't define the IO mode constants for the FileSystemObject, so you need to define them yourself:

Javascript code:
// In the global scope
var ForAppending = 8;
// Where you need to read the text file
theFile = fso.OpenTextFile(MsgPlus.ScriptFilesPath  + "\\data.txt", ForAppending, true);

or use their numerical value directly:
Javascript code:
theFile = fso.OpenTextFile(MsgPlus.ScriptFilesPath  + "\\data.txt", 8, true);

Source: FileSystemObject.OpenTextFile on DevGuru
RE: Writing files? by matty on 06-01-2010 at 04:33 PM

quote:
Originally posted by matty
Also, JScript doesn't define the IO mode constants for the FileSystemObject, so you need to define them yourself:
quote:
Originally posted by ultimatebuster
I looked at it, but I can't seems to write a file

code:
    var ForAppending = 8;

    var fso, theFile;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    theFile = fso.OpenTextFile("data.txt", ForAppending, true);
    theFile.WriteLine("Hello World!");
    theFile.Close();

OP did do that...
RE: Writing files? by Matti on 06-01-2010 at 04:39 PM

quote:
Originally posted by matty
OP did do that...
Oh dear, how could I have missed that? Was it because the code syntax wasn't highlighted? Was it because I just got back from a long day in school? Was it because I replied too fast?
* Matti hides.

In that case, matty's code should do the job just fine. :P
RE: Writing files? by matty on 06-01-2010 at 04:40 PM

It is ok my little padwan learner... now go write some code to make up for it :P

Not to hijack the thread but we really should consider maybe releasing PB2 of Screenshot Sender...