mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jul 2004
Posts: 12
I
Pikka bird
OP Offline
Pikka bird
I
Joined: Jul 2004
Posts: 12
How do i write a on text script whereby on text i will send a random file in a specific folder?

Joined: Apr 2004
Posts: 45
V
Ameglian cow
Offline
Ameglian cow
V
Joined: Apr 2004
Posts: 45
Code:
on *:text:[color:red]texthere[/color]:[color:red]#[/color]: {
  var %num = $rand(1,[color:red]20[/color])
  var %file = $+(",$findfile("[color:red]c:\path\to\folder\[/color]",*.*,%num),")
  dcc send $nick %file
}


You need to replace the parts in red:
for texthere, replace that with the key word you want to respond to.
for #, right now it means it responds to the texthere text in any channel window. You can change it to ? for PM windows, or #blah for a specific channel, et cetera. See /help on text for more info.
20 should be the total number of files you have in the folder, and c:\path\to\folder\ should point to the actual folder you're using. I haven't tested this, but no reason it shouldn't work.

-Venoman

Joined: Jul 2004
Posts: 12
I
Pikka bird
OP Offline
Pikka bird
I
Joined: Jul 2004
Posts: 12
Thank you.

Joined: Jul 2004
Posts: 12
I
Pikka bird
OP Offline
Pikka bird
I
Joined: Jul 2004
Posts: 12
there seems to be a problem..

* /dcc: insufficient parameters (line 4, script3.ini)

variable %file is not set automatically

Joined: Apr 2004
Posts: 45
V
Ameglian cow
Offline
Ameglian cow
V
Joined: Apr 2004
Posts: 45
you'll get that error sometimes if you replaced the number 20 with a number higher than the total # of files in the folder. Also make sure you specify the whole path to the folder correctly.

-Venoman

Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327

  • on *:text:texthere:#: {
    var %num = $rand(1,$findfile([color:red]c:\path\to\folder,*.*,0)[/color])
    var %file = $+(",$findfile(c:\path\to\folder\,*.*,%num),")
    dcc send $nick %file
    }


Change the parts in red.


New username: hixxy
Joined: Apr 2004
Posts: 45
V
Ameglian cow
Offline
Ameglian cow
V
Joined: Apr 2004
Posts: 45
ah, knew there was a way to list the total # of files in a folder, just couldn't think of it smile

-Venoman

Joined: Jul 2004
Posts: 12
I
Pikka bird
OP Offline
Pikka bird
I
Joined: Jul 2004
Posts: 12
i still get the invalid parameters, this is how it looks after i have changed everything.

Code:
 on *:text:@[JP]Rina-Uchiyama:#abcd:{ 
  var %num = $rand(1,$findfile(C:\Documents and Settings\FaBiAn\My Documents\My Pictures\Rina Uchiyama,*.*,0)) 
  var %file = $+(",$findfile(C:\Documents and Settings\FaBiAn\My Documents\My Pictures\Rina Uchiyama,*.*,%num),") 
  dcc send $nick %file
}  

Joined: Dec 2002
Posts: 788
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 788
Not exactly, sure why your getting invalid parameters.. try adding some checks:

On *:text:@trigger*:[color:red]#Channel
:{
var %dir = [color:red]C:\directory here\

if (!$isdir(%dir)) { echo -a ERROR: Folder doesnt exist. }
else {
var %num = $rand(1,$findfile(%dir,*.*,0))
var %file = $+(",$findfile(%dir,*.*,%num),")
if (!$isfile(%file)) { echo -a ERROR: File doesnt exist. }
else { dcc send $nick %file }
}
}
[/color]

Eamonn.

Joined: Jul 2004
Posts: 12
I
Pikka bird
OP Offline
Pikka bird
I
Joined: Jul 2004
Posts: 12
File doesnt exist. =\

Joined: Dec 2002
Posts: 788
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 788
Werid, try typing it from a command line:

//echo -> $findfile(C:\DIR\,*,$rand(1,$findfile(C:\DIR\,*,0)))

Replacing, C:\DIR\

Eamonn.

Joined: Jul 2004
Posts: 12
I
Pikka bird
OP Offline
Pikka bird
I
Joined: Jul 2004
Posts: 12
echo results.

-> C:\Documents and Settings\FaBiAn\My Documents\My Pictures\Rina Uchiyama\032.jpg

Joined: Jul 2004
Posts: 12
I
Pikka bird
OP Offline
Pikka bird
I
Joined: Jul 2004
Posts: 12
upz

Joined: Aug 2003
Posts: 1,831
I
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
Problem may be that the file (or a dir in the path) has two consecutive spaces.

Joined: Jul 2004
Posts: 12
I
Pikka bird
OP Offline
Pikka bird
I
Joined: Jul 2004
Posts: 12
they are all picture files. none of them has any spaces =\~

As for the folder, there are only 1 space

Joined: Apr 2004
Posts: 45
V
Ameglian cow
Offline
Ameglian cow
V
Joined: Apr 2004
Posts: 45
no no no. always ALWAYS enclose paths to files and folders in quotes. I suppose I should have done that in my example, so that's my fault. your path has spaces, which won't actually return the full path when put to use, unless you put it in quotes.

Code:
on *:text:@[JP]Rina-Uchiyama:#abcd:{ 
  var %num = $rand(1,$findfile("C:\Documents and Settings\FaBiAn\My Documents\My Pictures\Rina Uchiyama",*.*,0)) 
  var %file = $+(",$findfile("C:\Documents and Settings\FaBiAn\My Documents\My Pictures\Rina Uchiyama",*.*,%num),") 
  dcc send $nick %file
}


there ya go.

-Venoman


Link Copied to Clipboard