Shoutbox

Help for a Script Beginner - Open File in Scripts - 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: Help for a Script Beginner - Open File in Scripts (/showthread.php?tid=80794)

Help for a Script Beginner - Open File in Scripts by blueeyez on 01-08-2008 at 11:15 AM

hay guys...is there any method to open a file in a messenger live script to read/write from it?

thanks for ur help in advance
blueeyez


RE: Help for a Script Beginner - Open File in Scripts by Matti on 01-08-2008 at 05:37 PM

You can use the FileSystem ActiveXObject to open a text file, read from it and write to it.

code:
var Path = MsgPlus.ScriptFilesPath + "\\Stuff.txt"; //The path to the file to read / write to.
var IsUnicode = false; //Set this to true if you want to read / write in Unicode.

//Read the file
var FSO = new ActiveXObject("Scripting.FileSystemObject");
var File = FSO.GetFile(Path);
var TextStream = FSO.OpenAsTextStream(1, IsUnicode ? -1 : 0);
var Contents = TextStream.ReadAll();
TextStream.Close();
//Do something useful with Contents...

//Write the file
var Contents = "This is the new content of the file!";
var FSO = new ActiveXObject("Scripting.FileSystemObject");
var File = FSO.GetFile(Path);
var TextStream = FSO.OpenAsTextStream(2, IsUnicode ? -1 : 0);
TextStream.Write(Contents);
TextStream.Close();
Or, if you want to get really advanced, you could use the Windows API for this... but I doubt that as a beginner, you'd want to get on to something that complicated. :P

References:
FileSystemObject
TextStream object