Shoutbox

[HELP]File listing and getting it to work - 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]File listing and getting it to work (/showthread.php?tid=65519)

[HELP]File listing and getting it to work by Vector on 08-28-2006 at 09:52 PM

hi there!
i'm realy new to mpl! scripting and i need some help with getting this to work :)

i got it from mpscripts.net

i'm trying to list out the files from directory, and send the list of files in the chat.

this is what i got yet:


function OnEvent_ChatWndSendMessage(ChatWnd,Message)
{
    if(Message.match("^!list"))
    {
        var folder = Message.substr(6);
        var type = "1"
        //ChatWnd.SendMessage(folder);
        var stuff = ListFolders();
        ChatWnd.SendMessage(stuff);
    }
}

//Folder = folder to read files from
//Type: 0 = Full Path; 1 = Filename Only
//Returns array if files found otherwise false
function ListFiles(folder,type) {
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var dirFiles = new Array();
    if(fso.FolderExists(folder)) {
        f = fso.GetFolder(folder);
        files = new Enumerator(f.Files);
        if(files.atEnd()) return false;
        for (var i = 0; !files.atEnd(); files.moveNext())
        {
            if(type == 1)
                dirFiles[i++] = files.item();
            else {
                var temp = "" + files.item();
                var index = temp.lastIndexOf("\\");
                dirFiles[i++] = temp.substr(index+1);
            }
        }
        return dirFiles;
    } else
        return false;
}

i know that there are several thing i'm doing wrong but that is why i'm asking for some help :)

sry for my english and thank you..


RE: [HELP]File listing and getting it to work by Silentdragon on 08-28-2006 at 10:16 PM

It needs to be used like this:

code:
var list = ListFiles("C:\\",1);
Debug.Trace("First File in C:\\ is "+list[0]);
That would get a list of all files in C:\ and Debug.Trace the first file in the list.

So in your example you'd need to do this
code:
function OnEvent_ChatWndSendMessage(ChatWnd,Message)
{
    if(Message.match("^!list"))
    {
        var folder = Message.substr;
        var stuff = ListFolders(folder,1);
        ChatWnd.SendMessage(stuff.join("\r\n"));
    }
}
That would send a list of your files to your contact with each file on its own line.
RE: [HELP]File listing and getting it to work by Vector on 08-29-2006 at 09:46 PM

Thank You! :)