mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Aug 2004
Posts: 26
D
Danko Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Aug 2004
Posts: 26
How do i count the number of files in a .txt file and say it to the channel? (with a !count trigger)

Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Here's a simple one that will work with just the one file you put in.
Code:
on 1:Text:!count:#: {
   msg $chan There are $lines([color:blue]file[/color]) lines of text in [color:blue]file[/color].
}


Or...

Code:
on 1:Text:!count *:#: { 
    if ($isfile($2-)) {
      var %count = $numtok($2-,46)
      if ($gettok($2-,%count,46) == mrc || $gettok($2-,%count,46) == ini || $gettok($2-,%count,46) == txt || $gettok($2-,%count,46) == doc) { 
        msg $chan $2- has a total of $lines($2-) line(s) with a size total of $bytes($file($2-),kb).suf $+ .
      }
  }
}


This allows users on the channel to type !count <file>.
It will only work if the file actually exists on your computer.
It will only work if the extension is either .mrc, .ini, .txt, .doc.
You can add more extensions if you like.

Example:

[15:24] <Andy> !count mIRC.ini
[15:24] <Test> mIRC.ini has a total of 204 line(s) with a size total of 4.6KB.

They can also specify directories.

Example:

[15:25] <Andy> !count Channels\Channels.txt
[15:25] <Test> Channels\Channels.txt has a total of 19 line(s) with a size total of 2.4KB.

If yopu don't want this, the the first one I specified will work for just one file which might be up your alley.

Hope this helps. :sile:

Last edited by SladeKraven; 25/02/05 03:28 PM.
Joined: Nov 2004
Posts: 332
R
Fjord artisan
Offline
Fjord artisan
R
Joined: Nov 2004
Posts: 332
i dont think isaw saw a flood prot kraven
u may want to give him one
just in case


The Kodokan will move you, one way or another.
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
You're right, thanks ricky. smile

Danko, this code will prevent anyone who's already used the !count command from doing so again for 30 seconds.
Which as Ricky rightfully said, to add it because you do get idiots on IRC that will use the command roughly 4-5 times one after the other. If you think 30 seconds is too short, expand it to a greater duration.

set -u60 %count. [ $+ [ $nick ] ] on for example.

Code:
on 1:Text:!count:#: {
  if (%count. [ $+ [ $nick ] ]) { 
    return
  }
  else { 
    set -u30 %count. [ $+ [ $nick ] ] on
    msg $chan There are $lines([color:blue]file[/color]) lines of text in [color:blue]file[/color].
  }
}


Or as I suggested earlier...

Code:
on 1:Text:!count *:#: {
  if (%count. [ $+ [ $nick ] ]) { 
    return
  }
  else { 
    set -u30 %count. [ $+ [ $nick ] ] on
    if ($isfile($2-)) {
      var %count = $numtok($2-,46)
      if ($gettok($2-,%count,46) == mrc || $gettok($2-,%count,46) == ini || $gettok($2-,%count,46) == txt || $gettok($2-,%count,46) == doc) { 
        msg $chan $2- has a total of $lines($2-) line(s) with a size total of $bytes($file($2-),kb).suf $+ .
      }
    }
  }
}


Link Copied to Clipboard