mIRC Homepage
i need a script where it will search a script file for something then dlt it - but the prob is i know u can use the command write -dsWORD filename.txt

but if the text file was like

WORD bla
WORD bla2
WORD bla3

it would only delete WORD bla and would leave the other two there.
You can just make a simple while loop for that.

Code:
while ($read([color:red]file.txt[/color], w, [color:red]search-term[/color] $+ *) != $null) {
  write -ds $+ [color:red]search-term[/color] [color:red]file.txt[/color]
}
whered $1 come from
Sorry, it should have been the search-term, I just forgot to replace it.

I've edited the code.
everytime i use the command 2 things happen

1) when u try to open the txt file, wordpad comes up saying failed to open (but sometimes u can get in)

2) Mirc Lags out

i think their might b sumtin wrong with the loop but i dunno

EDIT: dunno about this but can a line ever be $null ?
Your code would only delete the first instance.

Code:
alias moo {
  var %x = $lines(test.txt)
  while (%x) {
    if ($+($1,*) iswm $read(test.txt,%x)) write $+(-dl,$readn) test.txt
    dec %x
  }
}


-Andy
modified it to this

Code:
on *:TEXT:!dlt:?:{
  moo
}
alias -l moo {  
  var %x = $lines(incompletefiles.txt)  while (%x) {    
    if ($+(onesikgypo,*) iswm $read(incompletefiles.txt,%x)) {
      write $+(-dl,$readn) incompletefiles.txt
      dec %x
    }
  }
}


and in incompletefiles

Code:
onesikgypo===============================
onesikgypo bla
onesikgypo bla2
onesikgypo bla3
sadf bak


i msg the bot with !dlt and nothing happens
You must have misread the code, because it does deletes every instance found. I tested with the following alias before I posted it.

Code:
alias deltxt {
  while ($read(test.txt, w, $1 $+ *) != $null) {
    write -ds $+ $1 test.txt
  }
}


test.txt contained these lines:
line 1
line 2
line 3
4th line
5th line

After doing "/deltxt line" it leaves only:
4th line
5th line
That lags the hell out of mIRC, and doesnt delete any lines for me.. smile

-Andy
alright i used ur code exactly how u used it just changed the text file, so

Code:
alias deltxt {
  while ($read(incompletefiles.txt, w, $1 $+ *) != $null) {
    write -ds $+ $1 incompletefiles.txt  
  }
}


then typed /deltxt onesikgypo

again mirc client just lags
That's very strange then, it works without problems here.

Tried on both mIRC 6.14 and with my bot 6.16, it works fine on either, though I don't think the version should be a problem.
lol damn this is annoying
Code:
alias moo {
  var %x = $lines(incompletefiles.txt)  while (%x) {
    if ($+($1,*) iswm $read(incompletefiles.txt,%x)) write $+(-dl,$readn) incompletefiles.txt
    dec %x 
  }
}


typed /moo onesikgypo

nothing dlted

can i ask where u got $readn from, or sumtin , i dunno not workin 4 me
$readn is the last line read from the text file.

The code does work, you just dont have it on the lines as I have it. Copy the code from the forum, paste in wordpad (/run wordpad) and then paste in the editor. Or just make sure you put the lines of code exactly how I have it.

-Andy
blah didnt realise it, lol works now, thnx
A much simpler and much much more efficient way to do this is:

Code:
filter -ffx [color:blue]filename.txt filename.txt[/color] [color:green]searchtext[/color] *

(Yes, the filename should be written twice).

This way the file is only opened and edited once, whereas using the other ways you've been shown here mIRC is effectively opening the file, looking at it, and closing it, twice per matching line using the $read() searching method, or in for the line-looping method it's actually opening the file, looking at it, and closing it twice per line - that's potentially hundreds of times for a relatively small file!
© mIRC Discussion Forums