I making a www page true mirc (stats), but i have a problem i can't solve, if the page exist i need the new one to be named #channel1.htm , but still the first one should be named #channel.htm . as you see i tested to do a rename of the file, but it write up to 20 diffrent files, so i end up with:

#channel1.htm
#channel2.htm
#channel3.htm

and so on, it should only create the file #channel1.htm since the #channel.htm does exist. and does #channel1.htm exist i need it to be #channel2.htm and the next one to #channel3.htm .

how can i solve this? i tested to return the value from pn as follow:

write -c $qt($mircdir\stats\ $+ $1 $+ $pn $+ .htm)
then i write the rest of the lines to the same file.

any ideas on how i can solve this one?

Code:
alias testar {
  write -c $qt($mircdir\stats\ $+ $1 $+ .htm)
}


alias pn {
  var %dir = $mircdirsystem\stats\, %ext = htm
  window -h @found.files
  noop $findfile(%dir,$+(*,%ext),0,0,aline @found.files $nopath($1-))
  var %match.nr = 1
  while ($fline(@found.files,$+(%match.nr))) {
    dline @found.files $v1
    inc %match.nr
  }
  var %nr = 1
  while ($line(@found.files,%nr)) {
    inc %nr
    inc %match.nr
  }
  window -c @found.files
  return %match.nr
}