Shoutbox

List file - 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: List file (/showthread.php?tid=65239)

List file by SnuZZer on 08-22-2006 at 02:08 PM

Hi.
I'm from Denmark and my english isn't good.

I want to make a list of files in a folder. The users types a command (Example: /list) and after the command /list they type the folder they want to make a list of.

Is this possible?

- Simon


RE: List file by markee on 08-22-2006 at 02:25 PM

code:
   files = new Array();
   fso = new ActiveXObject("Scripting.FileSystemObject");
   f = fso.GetFolder({folderpath}); //put folder path here with // instead of just /
   fc = new Enumerator(f.files);
   i = 0;
   for (; !fc.atEnd(); fc.moveNext())
   {
      files[i] = fc.item();
      i++;
   }

This will return the files within the folder in an array for you.
RE: List file by KnRd_WC on 08-22-2006 at 02:29 PM

Hi SnuZZer,

code:
fso=new ActiveXObject("Scripting.FileSystemObject")

function OnEvent_ChatWndSendMessage(ChatWnd,Message)
{
    if (Message.substr(0,5)=="/list") {
        Dir=Message.substr(6,Message.length-6);
        Dir=Dir.replace(/\\/gi,'\\\\');
        ListDirectory(Dir);
        return "";
    }
}

function ListDirectory(Directory)
{
    f = fso.GetFolder(Directory);
    var f1 = new Enumerator(f.files);
    for (; !f1.atEnd(); f1.moveNext()) {
        FileName = f1.item(); // Here's the file name
    }
    // SubFolders
    //var f2=new Enumerator(f.subfolders);
     //for (; !f2.atEnd(); f2.moveNext()) {
    //    ListDirectory(f2.item()); 
     //}
}

function OnGetScriptCommands ()
{
    commands="<ScriptCommands>";
    commands+="<Command>";
    commands+="<Name>list</Name>";
    commands+="<Description>List directory</Description>";
    commands+="</Command>";
    commands+="</ScriptCommands>";
    return commands;
}
------------------------------
EDIT : Argh, I'm too slow !!! :D
RE: List file by matty on 08-22-2006 at 03:07 PM

quote:
Originally posted by markee
f = fso.GetFolder({folderpath}); //put folder path here with // instead of just /
Incorrect, paths would be used like this : C:\\my\\test
RE: List file by SnuZZer on 08-22-2006 at 03:11 PM

Hi.
KnRd_WC i've tried this:

code:
fso=new ActiveXObject("Scripting.FileSystemObject")

function OnEvent_ChatWndSendMessage(ChatWnd,Message)
{
if (Message.substr(0,5)=="/list") {
Dir=Message.substr(6,Message.length-6);
Dir=Dir.replace(/\\/gi,'\\\\');
ListDirectory(Dir);
return "";
}
}

function ListDirectory(Directory)
{
f = fso.GetFolder(Directory);
var f1 = new Enumerator(f.files);
for (; !f1.atEnd(); f1.moveNext()) {
FileName = f1.item("C:\Documents and Settings\Basse\Dokumenter\Musik\Niarn - Antihelt"); // Here's the file name
}
// SubFolders
//var f2=new Enumerator(f.subfolders);
//for (; !f2.atEnd(); f2.moveNext()) {
// ListDirectory(f2.item());
//}
}

function OnGetScriptCommands ()
{
commands="<ScriptCommands>";
commands+="<Command>";
commands+="<Name>list</Name>";
commands+="<Description>List directory</Description>";
commands+="</Command>";
commands+="</ScriptCommands>";
return commands;
}

It says that the command doesn't exists :-/
RE: List file by ShawnZ on 08-22-2006 at 03:13 PM

quote:
Originally posted by SnuZZer
f1.item("C:\Documents and Settings\Basse\Dokumenter\Musik\Niarn - Antihelt");

why'd you add that there o.o
RE: List file by SnuZZer on 08-22-2006 at 03:16 PM

quote:
Originally posted by KnRd_WC
FileName = f1.item(); // Here's the file name[/code]

What else? :-/

RE: List file by KnRd_WC on 08-22-2006 at 03:33 PM

You don't have to add anything here ! :)

code:
FileName = f1.item();
'f1' is an enumerator which contain all files in the directory, so, with 'f1.moveNext()' you select the next entry and, with 'f1.item()' you get the text ! (I hope I'm comprehensible...)

'FileName' IS the file name !!! :S

If you want to list the directory content , type :
/list C:\Documents and Settings\Basse\Dokumenter\Musik\Niarn - Antihelt\ <-- don't forget this one !

And, for example you can try this :
code:
FileName = f1.item();
Debug.Trace(FileName);

;)
RE: List file by SnuZZer on 08-22-2006 at 06:54 PM

Hi.
I'm sorry!
I really don't understand!
If i write /list C:\Documents and Settings\Basse\Dokumenter\Musik\Niarn - Antihelt\ in the chatwindow nothing happens.

Shell i change the script?

code:
fso=new ActiveXObject("Scripting.FileSystemObject")

function OnEvent_ChatWndSendMessage(ChatWnd,Message)
{
if (Message.substr(0,5)=="/list") {
Dir=Message.substr(6,Message.length-6);
Dir=Dir.replace(/\\/gi,'\\\\');
ListDirectory(Dir);
return "";
}
}

function ListDirectory(Directory)
{
f = fso.GetFolder(Directory);
var f1 = new Enumerator(f.files);
for (; !f1.atEnd(); f1.moveNext()) {
FileName = f1.item(); // Here's the file name
}
// SubFolders
//var f2=new Enumerator(f.subfolders);
//for (; !f2.atEnd(); f2.moveNext()) {
// ListDirectory(f2.item());
//}
}

function OnGetScriptCommands ()
{
commands="<ScriptCommands>";
commands+="<Command>";
commands+="<Name>list</Name>";
commands+="<Description>List directory</Description>";
commands+="</Command>";
commands+="</ScriptCommands>";
return commands;
}

RE: List file by KnRd_WC on 08-22-2006 at 07:13 PM

Hi SnuZZer,

Look at this:

code:
//...............
function ListDirectory(Directory)
{
f = fso.GetFolder(Directory);
var f1 = new Enumerator(f.files);
for (; !f1.atEnd(); f1.moveNext()) {
FileName = f1.item(); // GET the filename
// Here, you get the file name in the variable 'FileName', and, that's all !! If you want to display the filename, in a Toast, for example, you may use that :
MsgPlus.DisplayToast("List Directory",FileName);
}
// SubFolders (If you want to include sub-folders, un-comment (lol, english ?) these lines :
//var f2=new Enumerator(f.subfolders);
//for (; !f2.atEnd(); f2.moveNext()) {
// ListDirectory(f2.item());
//}
}
//...............
I'd like to explain to you how this function works, but that's very hard, I can't find the words to say that... :(
RE: List file by SnuZZer on 08-22-2006 at 07:29 PM

Hi.
Oh cool! ;-)
I didn't no what FileName contained.

I now how to send a message, but if i want to send all the files in one message with a carriage return after every file, how  do i fix that?

Maybe it's a god idea to tell you what the plan for the script is.
The meaning is to show contacts what there is in a folder, for example in a folder with music.


RE: List file by KnRd_WC on 08-22-2006 at 07:42 PM

;)

code:
fso=new ActiveXObject("Scripting.FileSystemObject")

function OnEvent_ChatWndSendMessage(ChatWnd,Message)
{
if (Message.substr(0,5)=="/list") {
Dir=Message.substr(6,Message.length-6);
Dir=Dir.replace(/\\/gi,'\\\\');
ListDirectory(Dir,ChatWnd); // You have to send the ChatWnd value
return "";
}
}

function ListDirectory(Directory,Wnd) // 'Wnd' >> the message will be send to this window
{
f = fso.GetFolder(Directory);
var f1 = new Enumerator(f.files);
LIST="Directory content : "+Directory+"\n\n" // "\n" = Return
for (; !f1.atEnd(); f1.moveNext()) {
FileName = f1.item();
LIST+="   "+FileName+"\n" // add a tabulation, the file name and "\n"
}
Wnd.SendMessage(LIST); // when finished, send the message to the chat window (that's why you have to send 'ChatWnd' to the ListDirectory() function
}

function OnGetScriptCommands ()
{
commands="<ScriptCommands>";
commands+="<Command>";
commands+="<Name>list</Name>";
commands+="<Description>List directory</Description>";
commands+="</Command>";
commands+="</ScriptCommands>";
return commands;
}

Wow, Am I understandable ? :S

NOTE : The length of the message which will be sent is limited !!! ('cause of the MSN restrictions)

Edit : I know, this code can be optimized, but I wanted to do something easy and understandable, for example :
code:
Dir=Message.substr(6,Message.length-6);
Dir=Dir.replace(/\\/gi,'\\\\');
ListDirectory(Dir,ChatWnd);

>>>>>
code:
ListDirectory(Message.substr(6,Message.length-6).replace(/\\/gi,'\\\\'),ChatWnd);


or

code:
FileName = f1.item();
LIST+="   "+FileName+"\n"
>>>>>
code:
LIST+="   "+f1.item()+"\n";


;)


RE: List file by SnuZZer on 08-23-2006 at 11:06 AM

Hi.
Og thanks!! I can't thanks enough!!

It's [b]lovely[/k] that people would helps!! (L)


RE: List file by SnuZZer on 08-23-2006 at 11:38 AM

Hi.
Oh, i'm sorry. I don't want to abuse you, but..

I tried to delete the path before the filename, but it doesn't work.
I tried this:

code:
Filnavn = Enum.item();
VisFilnavn = Filnavn.replace(/Directory/g,"");

RE: List file by KnRd_WC on 08-23-2006 at 12:39 PM

Erf... I'm sorry too... I can't find a way to remove the directory name...

I tried that :

code:
FileName=FileName.substr(Directory.length,FileName.length-Directory.length);


Unsuccessfully...

And, I tried that too, just for testing :

code:
FileName=FileName.replace(/c/gi,"a");


Unsuccessfully too. It seems it's impossible to use these functions on the 'Enum.item()' value. Is it a 'special' string ?

Please help, i'm going to learn something too ;)

Note : In my code : 'FileName=f1.item()' ;)

----------------------------------------------

EDIT: LOL !!!!

Just use .replace() in the last string !!! 'LIST' :

code:
repl = new RegExp("("+Directory+")","gi");
Wnd.SendMessage(LIST.replace(repl,""));


Lol, just 5 minutes to find the solution :P
RE: List file by SnuZZer on 08-23-2006 at 12:52 PM

Hi.
I have changed the variabel names to danish words :-$

I doesn't work. It shows the path :-/

code:
function ListDirectory(Directory,Wnd)
{
    Hent = Info.GetFolder(Directory);
    var Enum = new Enumerator(Hent.files);
    Liste = "Sti: " + Directory + "\n\n"
    for (; !Enum.atEnd(); Enum.moveNext())
    {
        Filnavn = Enum.item();
        Liste += Filnavn + "\n"
    }
    FjernSti = new RegExp("("+Directory+")","gi");
    Wnd.SendMessage(Liste.replace(FjernSti,""));
}

RE: List file by KnRd_WC on 08-23-2006 at 12:57 PM

Really ?? I tried with your function, and it works fine....

quote:
Sti: \ <-- Maybe you want to remove that ??? (If you want to keep the path name here, see the function bottom)

  AUTOEXEC.BAT
  BOOT.BKK
  boot.ini
  Bootfont.bin
  CONFIG.SYS
  IO.SYS
  MSDOS.SYS
  NTDETECT.COM
  ntldr
  pagefile.sys
  sqmnoopt00.sqm


To keep the path name "Sti : C:\", for example :

code:
function ListDirectory(Directory,Wnd)
    {
    Hent = Info.GetFolder(Directory);
    var Enum = new Enumerator(Hent.files);
    Liste=""
    for (; !Enum.atEnd(); Enum.moveNext())
    {
    Filnavn = Enum.item();
    Liste += Filnavn + "\n"
    }
    FjernSti = new RegExp("("+Directory+")","gi");
    Wnd.SendMessage("Sti: " + Directory.replace(/\\\\/gi,'\\')+ "\n\n"+Liste.replace(FjernSti,""));
    }

RE: List file by SnuZZer on 08-23-2006 at 01:05 PM

Hi.
That's wierd!
The code you show me there returns this:
[k]Sti: C:\Documents and Settings\Basse\Dokumenter\Billeder

C:\Documents and Settings\Basse\Dokumenter\Billeder\avatar.gif[/k]

The meaning is to return this:
[k]Sti: C:\Documents and Settings\Basse\Dokumenter\Billeder

avatar.gif[/k]


RE: List file by KnRd_WC on 08-23-2006 at 01:11 PM

Yeah, that's really strange.... The script works fine for me.... :S

Maybe you can try with my code :

code:
Info=new ActiveXObject("Scripting.FileSystemObject")

function OnEvent_ChatWndSendMessage(ChatWnd,Message)
{
if (Message.substr(0,5)=="/list") {
ListDirectory(Message.substr(6,Message.length-6).replace(/\\/gi,'\\\\'),ChatWnd);
return "";
}
}

function ListDirectory(Directory,Wnd)
{
Hent = Info.GetFolder(Directory);
var Enum = new Enumerator(Hent.files);
Liste=""
for (; !Enum.atEnd(); Enum.moveNext())
{
Filnavn = Enum.item();
Liste += Filnavn + "\n"
}
FjernSti = new RegExp("("+Directory+")","gi");
Wnd.SendMessage("Sti: " + Directory.replace(/\\\\/gi,'\\')+ "\n\n"+Liste.replace(FjernSti,""));
}

function OnGetScriptCommands ()
{
commands="<ScriptCommands>";
commands+="<Command>";
commands+="<Name>list</Name>";
commands+="<Description>List directory</Description>";
commands+="</Command>";
commands+="</ScriptCommands>";
return commands;
}

And try : /list C:\

^o)
RE: List file by SnuZZer on 08-23-2006 at 01:19 PM

Hi!
That works!!
But, i'm a perfectionist and i would like to delete the "\" before the filename :-D

That sounds simple, but.. You use commands i don't know, but i'm learning when i see codes :-D

Ohh.. I'm so sorry to be troublesome :-(


RE: RE: List file by KnRd_WC on 08-23-2006 at 01:22 PM

Hi !

quote:
Originally posted by SnuZZer
Hi!
That works!!
But, i'm a perfectionist and i would like to delete the "\" before the filename :-D

Ohh.. I'm so sorry to be troublesome :-(


Instead of using:
quote:
/list C:\Documents and Settings\Basse\Dokumenter\Billeder

Use :
quote:
/list C:\Documents and Settings\Basse\Dokumenter\Billeder\

It was a pleasure to help you, and I hope you understand how the script works... If not, I advise you to use Google to find more infos about these functions ;)
RE: List file by SnuZZer on 08-23-2006 at 01:25 PM

Hi.
Yeah, that works! <3

Thanks!! (L)


RE: List file by SnuZZer on 08-23-2006 at 01:33 PM

Hi.
Oh, i'm sorry... If you want.. A last question.

How can i make sure that the users remember the last "\"?

I've tried this:

code:
        if (Message.substr(Lengde-1, Lengde) == "\")
        {
            Message = Message;
        }
        else
        {
            Message = Message + "\";
        }

I think this was to much for a newbie like me, but now we are finish :-P
RE: List file by KnRd_WC on 08-23-2006 at 02:32 PM

Hi !

code:
function OnEvent_ChatWndSendMessage(ChatWnd,Message)
{
if (Message.substr(0,5)=="/list") {
if (Message.substr(Message.length-1,1)!="\\") {
// Get the Message string length using that : Message.length
// To get the last letter : Message.length-1
// EX : TEST (len = 4), the first character is at position 0, so, the last T is at position 3 (4-1)
// If you use "\", your script will not work, because "\" is for specials characters, EX : "\n" >> Return.
// So, you have to use "\\"
    Message+="\\"
// If the last letter is not ('!=') "\", just add ('+=') \ ('\\') to Message string !
}
ListDirectory(Message.substr(6,Message.length-6).replace(/\\/gi,'\\\\'),ChatWnd);
return "";
}
}

RE: List file by SnuZZer on 08-23-2006 at 03:32 PM

Hi!
Og thanks!! (L)