What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [Help]Reading a file/Opening a file

[Help]Reading a file/Opening a file
Author: Message:
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
RE: [Help]Reading a file/Opening a file
I can't test this right now, but this should do the trick.

JScript code:
var FSO = new ActiveXObject("Scripting.FileSystemObject"); // define globally
 
/* StringInFolder: return the next line of a file after a string match
- Folder: path to a folder to search
- String: text to search for in file
- Multi (optional): if true, an array for multiple matches will be returned */

function StringInFolder(Folder, String, Multi)
{
    var Folder = FSO.GetFolder(Path);
    var Return = [];
    for (var Enum = new Enumerator(Folder.Files), !Enum.atEnd(), Enum.moveNext())
    {
        var File = Enum.item();
        var Stream = File.OpenAsTextStream(1, -1);
        if (!Stream.AtEndOfStream) // shouldn't be empty
        {
            var Text = Stream.ReadAll().split("\r\n");
            var NextLine = false;
            for (var Line in Text)
            {
                if (NextLine) // yes, we matched the previous line
                {
                    if (Multi) // do we want an array of matches?
                    {
                        Return.push(Line);
                        NextLine = false;
                    }
                    else
                    {
                        return Line;
                    }
                }
                else if (Line.indexOf(String) !== -1) // found it!
                {
                    NextLine = true; // flag to check the next line
                }
            }
        }
        Stream.Close();
    }
}
 
var Result = StringInFolder("C:\\", "test", true); // example usage


This post was edited on 08-12-2010 at 11:41 AM by whiz.
08-12-2010 11:15 AM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[Help]Reading a file/Opening a file - by Monckey100 on 08-12-2010 at 10:29 AM
RE: [Help]Reading a file/Opening a file - by whiz on 08-12-2010 at 11:15 AM
RE: [Help]Reading a file/Opening a file - by Matti on 08-12-2010 at 07:24 PM
RE: [Help]Reading a file/Opening a file - by Monckey100 on 08-12-2010 at 10:27 PM
RE: [Help]Reading a file/Opening a file - by Mnjul on 08-13-2010 at 08:25 AM


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