What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Writing files?

Writing files?
Author: Message:
ultimatebuster
Junior Member
**


Posts: 17
Joined: Oct 2008
O.P. Writing files?
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
05-21-2010 02:46 AM
Profile E-Mail PM Find Quote Report
Chris4
Elite Member
*****

Avatar

Posts: 4461
Reputation: 84
33 / Male / Flag
Joined: Dec 2004
RE: Writing files?
Are you looking for the Scripting Documentation?

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

Hope that helps.
Twitter: @ChrisLozeau
05-21-2010 03:22 AM
Profile PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Writing files?
Check a look at MSDN for Scripting.FileSystemObject. It has functions called CreateTextFile and WriteFile and Read file etc.
05-21-2010 10:24 AM
Profile E-Mail PM Find Quote Report
ultimatebuster
Junior Member
**


Posts: 17
Joined: Oct 2008
O.P. RE: Writing files?
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();
05-21-2010 08:50 PM
Profile E-Mail PM Find Quote Report
n3mo
New Member
*


Posts: 1
Joined: May 2010
RE: Writing files?
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.
05-31-2010 07:35 PM
Profile PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Writing files?
quote:
Originally posted by n3mo
js code:
theFile = fso.OpenTextFile(MsgPlus.ScriptFilesPath  + "/data.txt", ForAppending, true);


That is wrong...
js code:
theFile = fso.OpenTextFile(MsgPlus.ScriptFilesPath  + "\\data.txt", ForAppending, true);
05-31-2010 08:08 PM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Writing files?
Also, JScript doesn't define the IO mode constants for the FileSystemObject, so you need to define them yourself:
js 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:
js code:
theFile = fso.OpenTextFile(MsgPlus.ScriptFilesPath  + "\\data.txt", 8, true);
Source: FileSystemObject.OpenTextFile on DevGuru
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
06-01-2010 03:58 PM
Profile E-Mail PM Web Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Writing files?
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...
06-01-2010 04:33 PM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Writing files?
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
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
06-01-2010 04:39 PM
Profile E-Mail PM Web Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Writing files?
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...

This post was edited on 06-01-2010 at 04:40 PM by matty.
06-01-2010 04:40 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On