List file |
Author: |
Message: |
SnuZZer
Full Member
Posts: 114
32 / /
Joined: Jun 2006
|
O.P. List file
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
|
|
08-22-2006 02:08 PM |
|
|
markee
Veteran Member
Posts: 1622 Reputation: 50
36 / /
Joined: Jan 2006
|
RE: List file
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.
This post was edited on 08-22-2006 at 02:26 PM by markee.
|
|
08-22-2006 02:25 PM |
|
|
KnRd_WC
Junior Member
Florian PAQUET
Posts: 74 Reputation: 1
35 / /
Joined: Aug 2006
|
RE: List file
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 !!!
This post was edited on 08-22-2006 at 02:31 PM by KnRd_WC.
|
|
08-22-2006 02:29 PM |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
Joined: Dec 2002
Status: Away
|
RE: List file
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
|
|
08-22-2006 03:07 PM |
|
|
SnuZZer
Full Member
Posts: 114
32 / /
Joined: Jun 2006
|
O.P. RE: List file
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
|
|
08-22-2006 03:11 PM |
|
|
ShawnZ
Veteran Member
Posts: 3146 Reputation: 43
32 / /
Joined: Jan 2003
|
RE: List file
quote: Originally posted by SnuZZer
f1.item("C:\Documents and Settings\Basse\Dokumenter\Musik\Niarn - Antihelt");
why'd you add that there o.o
Spoiler: the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
|
|
08-22-2006 03:13 PM |
|
|
SnuZZer
Full Member
Posts: 114
32 / /
Joined: Jun 2006
|
O.P. RE: List file
quote: Originally posted by KnRd_WC
FileName = f1.item(); // Here's the file name[/code]
What else?
|
|
08-22-2006 03:16 PM |
|
|
KnRd_WC
Junior Member
Florian PAQUET
Posts: 74 Reputation: 1
35 / /
Joined: Aug 2006
|
RE: List file
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 !!!
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);
This post was edited on 08-22-2006 at 03:38 PM by KnRd_WC.
|
|
08-22-2006 03:33 PM |
|
|
SnuZZer
Full Member
Posts: 114
32 / /
Joined: Jun 2006
|
O.P. RE: List file
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;
}
|
|
08-22-2006 06:54 PM |
|
|
KnRd_WC
Junior Member
Florian PAQUET
Posts: 74 Reputation: 1
35 / /
Joined: Aug 2006
|
RE: List file
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...
This post was edited on 08-22-2006 at 07:18 PM by KnRd_WC.
|
|
08-22-2006 07:13 PM |
|
|
Pages: (3):
« First
[ 1 ]
2
3
»
Last »
|
|