mIRC Home    About    Download    Register    News    Help

Print Thread
#175752 27/04/07 10:05 PM
Joined: Feb 2007
Posts: 33
H
harl91 Offline OP
Ameglian cow
OP Offline
Ameglian cow
H
Joined: Feb 2007
Posts: 33
i need a script that will randomly pick a file name in a folder that is located in the same folder that mirc is in.

for example, if i have three files

a.map
b.map
c.mao

i want it to randomly pick a file and set it into a variable

Last edited by harl91; 27/04/07 10:20 PM.
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
First you need to count how many files there are:

var %count = $findfile(c:\path\name\,*.*,0,1)

then pick a random number from 1 to %count:

var %count = $rand(1,%count)

then pick the random'th file:

var %count = $findfile(c:\path\name\,*.*,%count,1)

You can also make some changes to look at *.map instead of *.*, or remove the ,1 to make it look in subfolders beneath.

Joined: Mar 2003
Posts: 612
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Mar 2003
Posts: 612
Code:
//echo $findfile(C:mirc/folder,*.map,$rand(1,$findfile(C:mirc/folder,*.map,0,0)),0)


btk


billythekid
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
maroon already gave the answer. Your one-liner is based on the same idea except it's sloppier (0 for the [depth] parameter, forward slashes in paths, no slash after the drive letter; all these are non-standard, although tolerated).


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Mar 2003
Posts: 612
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Mar 2003
Posts: 612
how come a depth of 0 is wrong? I figured that if you want to go zero dirs deeper then 0 would be the correct number, 1 should check that folder and one deeper imo, although i didnt test this, i've always used 0 deep for that folder only.

as for the slashes i did notice that but couldn't be bothered changing it! lol

btk


billythekid
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
Originally Posted By: billythekid
how come a depth of 0 is wrong? I figured that if you want to go zero dirs deeper then 0 would be the correct number, 1 should check that folder and one deeper imo, although i didnt test this, i've always used 0 deep for that folder only.

snip


depth 0 is the same as dept 999999, the same way /dcc maxcps of 0 is same as 999999. Depth 1 does 1-level search, so it searches c:\path\name\ only, while dept 2 would also search in c:\path\name\subdir\ - so if you're wanting to only get files from the base folder, anything besides level-1 wastes time by searching for total-files in all subfolders.

If you're just searching for the 1st file, and there's at least 1 matching file in the base folder, then there is no difference whether or not you limit the depth or not.

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Actually, anything <= 0 is treated as 1, not 999999. The latter is treated as it is, ie makes $findfile scan up to 999,999 directories deep.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
Sorry, you're right, it was the absence of the depth parameter that was treated as infinite depth. I did notice that $findfile($mircdir,*.mrc,0,%null_variable) returns nothing at all, and isn't the same as $findfile($mircdir,*.mrc,0). I wonder if it's supposed to be that way, though you can always sanitize the variable by changing $null into 0 or 999999.

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
I thought the same thing, but I tested it before going to post, and the test showed quite easily that I was thinking incorrectly.
If the depth parameter is omitted, then it does the search of the specified directory and any directories and sub-directories thereof.

Joined: Feb 2007
Posts: 33
H
harl91 Offline OP
Ameglian cow
OP Offline
Ameglian cow
H
Joined: Feb 2007
Posts: 33
maroons was fine, here it is

Code:
    set %bot.numberofmaps  $findfile(c:/winbolo/maps/,*.map,0,1)
    set %bot.mapnumber $rand(1,%bot.numberofmaps)
    set %bot.randmap1 $findfile(c:/winbolo/maps/,*.map,%bot.mapnumber,1)
    set %bot.randmap $right( %bot.randmap1 , -16 )

Joined: Mar 2006
Posts: 395
T
Pan-dimensional mouse
Offline
Pan-dimensional mouse
T
Joined: Mar 2006
Posts: 395
* JD laughs and thinks:

Code:
set %file $r(a,c) $+ .map


I write this because it could be his $mircdir or any other directory that contains non map files.

Last edited by The_JD; 06/05/07 05:04 AM.

[02:16] * Titanic has quit IRC (Excess Flood)

Link Copied to Clipboard