Originally Posted By: Glenn Barnas

As for basic search/replace, here's the basic idea...
 Code:
$SearchData = 'xyzzy'           ; insert when line containing this is found
$InsertData = 'AbraCadabra'     ; data line to insert
$RootPath = 'D:\folder...' ; root path where files live
$Files = DirList($RootPath, 6) ; return a list of all files with complete paths
For Each $File in $Files
  Move $File 'WorkFile.tmp' ; rename the file
  If Open(2, 'workfile.tmp')
    $ = RedirectOutput($File) ; output to original file
    $Line = ReadLine(2)
    While Not @ERROR
      If InStr($Line, $SearchData)
        $InsertData ?        ; output extra (inserted) line
      EndIf
    $Line ?                  ; output original line
    $Line = ReadLine(2)
    Loop
    $ = Close(2)
    $ = RedirectOutput('')  ; close output file
    Del 'workfile.tmp'
  EndIf
Next

This is UNTESTED, and presented to illustrate the logic flow. This could easily be modified to REPLACE a line or APPEND a line rather than INSERT a line. A nice mod might be to define a var $MODE, and use a Case statement to Insert, Replace, or Append depending on the value of $MODE.

Glenn


I've started to work on this more intensively today, and took this code to start with. I understand that this also uses dirlist.udf. The basic works fine, but what's strange, is that the script doesn't do anything with file #1, it just cuts and paste file#1 into file#2(pastes into the beginning of file). File #2 is being processed, and the insertion is ok, but as you see.. the file#1 is then a part of this file. After this file#1 gets deleted, that is, this isn't totally true, the file is being put where the kix-script is started from, and has been renamed to 'workfile.tmp'

Haven't tried with more then 2 files yet.


Jon


Edited by Curious (2008-04-01 04:11 PM)
_________________________
I was placed on earth to do a job. Right now I have so much to do, I will never die..