mIRC Home    About    Download    Register    News    Help

Print Thread
I
icybergie
icybergie
I
How do i write a on text script whereby on text i will send a random file in a specific folder?

V
Venoman
Venoman
V
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

I
icybergie
icybergie
I
Thank you.

I
icybergie
icybergie
I
there seems to be a problem..

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

variable %file is not set automatically

V
Venoman
Venoman
V
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,321
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,321

  • 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.

V
Venoman
Venoman
V
ah, knew there was a way to list the total # of files in a folder, just couldn't think of it smile

-Venoman

I
icybergie
icybergie
I
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: 787
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 787
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.

I
icybergie
icybergie
I
File doesnt exist. =\

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

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

Replacing, C:\DIR\

Eamonn.

I
icybergie
icybergie
I
echo results.

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

I
icybergie
icybergie
I
upz

I
Iori
Iori
I
Problem may be that the file (or a dir in the path) has two consecutive spaces.

I
icybergie
icybergie
I
they are all picture files. none of them has any spaces =\~

As for the folder, there are only 1 space

V
Venoman
Venoman
V
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