mIRC Homepage
Posted By: Wragg /write command - 21/11/04 02:15 PM
since this was not changed from old 6.0x versions (and maybe even before that) i give new request

since mirc can only write lines into filled .txt files i personally think that it would be far much better to add code so mirc can write lines to an EMTPY .txt file

and i think on this:

//write -l10 test.txt line ten

if file is empty then mirc will write this on 1st line not on 10th line

same goes for //write -il10 test.txt line ten

maybe this is not some MAJOR thing but some users could find it useful...

FiberOptics made this code that can come handy for those who needs things like this:

alias writeline {
if $2 <= $lines($1) { write -l $+ $2 $1 $$3- }
else { write $1 $str($lf,$calc($2 - $v2 - 1)) $+ $$3- }
}

Usage: /writeline <file> <line nr.> <data>

Copyright (C) FiberOptics 2004 laugh
Posted By: TroyBoy Re: /write command - 24/11/04 12:17 PM
Yes, I ran into that problem a couple of years ago. Its annoying (like many of mircs limitations).
I ended up having to code a workaround.
Posted By: FiberOPtics Re: /write command - 25/11/04 02:36 AM
Now that I think of it, I didn't add any support for a filepath which contains multiple spaces. Also, I've finally found the time to play around with COM objects, and have had quite some fun playing with these new toys. They can do things that mIRC can't do, although they may not be the most stable thing at times.

This snippet allows for paths with multiple spaces if enclosed with " ", and can write to virtually any line number, within the limits by Windows. As a test, I wrote to line number 1,000,000 (yes, you read it right), with nothing preceeding it.

Code:
alias writeline {

  ;  Usage:   /writeline &lt;file&gt; &lt;line&gt; &lt;data&gt;
  ;
  ;  Filepath may contain spaces if surrounded by " "
  ;
  ;  Example: /writeline "c:\program files\mirc\test.txt" 10000 testing
  ;            will write "testing" on line nr. 10000 in test.txt, 
  ;            if c:\program files\mirc exists.
  ;         
  ;           /writeline test.txt 15 another test
  ;            will write "another test" on line 15 in test.txt
  ;            in the mIRC folder

  var %file = $iif("*"* iswm $1-,$gettok($1-,1,34),$1)
  tokenize 32 $iif("*"* iswm $1-,$gettok($1-,2-,34),$2-)
  if $2 == $null { return }
  var %lines = $lines(%file)
  if $1 &lt;= %lines { write -l $+ $1 $+(",%file,") $2- | return }
  .comopen fso_1 Scripting.FileSystemObject
  if $comerr { return }
  .comclose fso_1 $com(fso_1,OpenTextFile,1,bstr,%file,uint,8,bool,true,dispatch* fso_2) 
  if $com(fso_2) {
    !.echo -q $com(fso_2,WriteBlankLines,1,uint,$calc($1 - %lines - 1))
    !.echo -q $com(fso_2,Writeline,1,bstr,$2-) 
    !.echo -q $com(fso_2,Close,1)
    .comclose fso_2
  }
}


This COM snippet won't work in mIRC 6.03, because back then, it seems mIRC had trouble creating an object through dispatch*. It works fine on mIRC 6.16 though.
© mIRC Discussion Forums