mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Oct 2005
Posts: 122
O
Vogon poet
OP Offline
Vogon poet
O
Joined: Oct 2005
Posts: 122
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.

Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
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]
}

Joined: Oct 2005
Posts: 122
O
Vogon poet
OP Offline
Vogon poet
O
Joined: Oct 2005
Posts: 122
whered $1 come from

Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Sorry, it should have been the search-term, I just forgot to replace it.

I've edited the code.

Joined: Oct 2005
Posts: 122
O
Vogon poet
OP Offline
Vogon poet
O
Joined: Oct 2005
Posts: 122
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 ?

Last edited by onesikgypo; 12/11/05 07:36 AM.
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
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

Joined: Oct 2005
Posts: 122
O
Vogon poet
OP Offline
Vogon poet
O
Joined: Oct 2005
Posts: 122
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

Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
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

Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
That lags the hell out of mIRC, and doesnt delete any lines for me.. smile

-Andy

Joined: Oct 2005
Posts: 122
O
Vogon poet
OP Offline
Vogon poet
O
Joined: Oct 2005
Posts: 122
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

Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
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.

Joined: Oct 2005
Posts: 122
O
Vogon poet
OP Offline
Vogon poet
O
Joined: Oct 2005
Posts: 122
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

Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
$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

Joined: Oct 2005
Posts: 122
O
Vogon poet
OP Offline
Vogon poet
O
Joined: Oct 2005
Posts: 122
blah didnt realise it, lol works now, thnx

Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
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!


Spelling mistakes, grammatical errors, and stupid comments are intentional.

Link Copied to Clipboard