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 |
|
|
Chris4
Elite Member
Posts: 4461 Reputation: 84
33 / /
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.
|
|
05-21-2010 03:22 AM |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
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 |
|
|
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 |
|
|
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 |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
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 |
|
|
Matti
Elite Member
Script Developer and Helper
Posts: 1646 Reputation: 39
32 / /
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
|
|
06-01-2010 03:58 PM |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
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 |
|
|
Matti
Elite Member
Script Developer and Helper
Posts: 1646 Reputation: 39
32 / /
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.
|
|
06-01-2010 04:39 PM |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
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
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 |
|
|
|