mIRC Home    About    Download    Register    News    Help

Print Thread
#170179 04/02/07 07:26 AM
Joined: Jan 2006
Posts: 40
D
DjJax Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Jan 2006
Posts: 40
alias buscar {
set %Loop 1
:loop
set %dani $findfile($scriptdir,*.org,%loop)
//echo -a $read(%dani,t,varela)
//echo -a %dani
inc %loop
if %loop > 7 { halt }
goto loop
}

i want search on my files the word varela any sugestion thank you


DjJax #170195 04/02/07 05:01 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Try this (while is always better than goto):
Code:
alias SearchFiles {
  var %cnt = 1
  var %files = $findfile($scriptdir,*.org,0)
  while (%cnt <= %files) {
    var %file = $findfile($scriptdir,*.org,%cnt)
    if ($read(%file,w,* $+ $1- $+ *) {
      echo -a 03 $+ $v1 04found in03 %file $+ 04.
    }
    inc %cnt
  }
}


Use:
/SearchFiles varela


Invision Support
#Invision on irc.irchighway.net
Riamus2 #170198 04/02/07 05:19 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Using $findfile in a loop this way is a bad idea, because this is what it does:

$findfile will loop through the files in the directory until it finds the %cnt'th matching file in each iteration of that loop.

So when %cnt is 1, it finds the first file.

%cnt = 1; files found = a.txt

When it's 2, it'll find the first two files, and so on:

%cnt = 2; files found = a.txt b.txt
%cnd = 3; files found = a.txt b.txt c.txt

---

Now, if we use $findfiles built-in looping functionality instead, each file will only be found once:

Code:
alias -l callback { 
  if ($read($1-,nw,$+(*,%search,*))) { echo -a $+($chr(3),03,$v1 $chr(3),04found in,$chr(3)03 $1-,$chr(3),04.) }
}
alias searchfiles { 
  set -u %search $1-
  noop $findfile($scriptdir,*.org,0,callback $1-) 
}

hixxy #170200 04/02/07 06:26 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Ah. Thanks. I don't use it for much, so didn't know about that. laugh


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard