I was troubling a little bit with that run-part of the script, and working with another way to fix the zip-extraction, when I looked in here and saw your post Glenn. I was working on something in that direction, byt thanks (once again..) for your time and help.

Now my script is doing almost everything I want it to, I am sure the code can be written much better, but anyhow, it does what I need it to. I will look a bit on trying to make udf of some parts of the script, see what I can make out of it.

Here's the script for now ( Right now it runs and has finished unpacking 200 zip-files, giving a bit under thousand files (totally abouut 10 gigs), now being rewritten and inserted the correct line. Works like a charm.. Not far from it anyway
Some text is written in norwegian.


 Code:

; Routine to search given directory for textfiles
; Uses DirList()Udf to search through Directory.
; Scans files in spesific directory and search for specific text
; When found - Dependent on file-naming, Insert line with different text ($InsertData) from var $Kommunenr
; every time text is found (numerous times in one single file).

; Version 1.0 - 20080402

; Necessary File-structure: 
	; d:\Sosi - Root-Dir
	; d:\Sosi\Zip - Zip-files is placed here
	; Rest of needed dirs is created in the script

;Dependecies: Dirlist()udf - Embedded in script
	;7z.exe must reside in zip-dir


;Defined Vars
$ZipDir = 'd:\sosi\zip\'
$7z = $ZipDir + '7z.exe'
$zipOutDir = $ZipDir +'Utpakket\'
$ZipSyntax = $7z + ' e ' + $ZipDir  +'*.zip *.sos -y -o'+$ZipOutDir
$SearchData = 'objtype'           ; insert when line containing this is found
$RootPath = 'd:\sosi\' ; root path where files live
$Original = 'Zip\Utpakket\'
$Files = DirList($RootPath+$Original, 2) ; return a list of all files with complete paths
$LogDir = 'Log\'  ; Log-dir
$LogFile = $RootPath+$logdir+'logfile.txt' ; Logfile-placement 
$counter = 0  ; Counter for printing # of files on screen
$WorkDir = 'WorkDir\'
$WorkFile = $RootPath+$Workdir+'WorkFile.tmp'
$OutPutDir = $RootPath + 'OutDir\'


;Create Necessary directories.. if already existing, empty thees ones.
If NOT Exist ($ZipOutDir) MD ($ZipOutDir)
  Else Del $ZipDir+$ZipOutDir
EndIf

If Exist ($logfile) Del ($logfile)  ; Check if log-file exists, if it does, delete it
  Else MD ($RootPath+$logdir)  ; If log-dir doesn't exist, create it
EndIf

If NOT Exist ($RootPath+WorkDir) MD ($RootPath+WorkDir)  
EndIf

If NOT Exist ($OutPutDir) MD ($OutPutDir)
  Else Del $OutPutDir
EndIf


;Running zip-routine:

;7zip kommando for å pakke gitte filtyper til ett fast område: 
; '7z e zipfil.zip *.sos -od:\sosi\zip\utpakket' (eller bare -outpakket om du står i Dir over)


$Cmd = '%COMSPEC% /c'
$Cmd = $Cmd + $ZipSyntax

Shell $Cmd

?
? "Zip-filer pakket ut og skrevet til fil.."  ; Confirmation after zip-ectraction
Sleep 10


;Checking each file for given text, starts here..
CLS

For Each $File In $Files

 $counter = $counter+1  ; Counter to use on screen and in logfile.
  $FileProcessed = SubStr ("$file",22,30)  ;Extract filename from $file
  ? "Skriver Fil# " $counter " " $fileprocessed " til fil.."  ; Display on screen file-progress.
  Open(1, $logfile, 5 )  ;Write all on screen to log-file
  WriteLine(1 , "Skriver Fil# "+ $counter + " "+ $fileprocessed + " til fil.." + @CRLF)
  
  ;Sjekke if file is N50-data
  $kommunenr = SubStr ("$file", 22,4)   ; File is probably n50
  
  ; Check if file is Fkb-data
  If SubStr("$file",22,2)='32' $kommunenr = SubStr("$file",25,4)
  EndIf
   
  ;Check if file is N250-data
  If SubStr("$file",22,3)='08_' OR SubStr("$file",22,3)='06_' 
  	If SubStr("$file",22,3)='08_' $kommunenr = SubStr("$file",22,2)+'00'
  	EndIf
  	
  	If SubStr("$file",22,3)='06_' $kommunenr = SubStr("$file",22,2)+'00'
  	EndIf
  EndIf  	
    	
  $InsertData = '..KOMM '+ $kommunenr  ;$kommunenr will decide which text to put in written out-file 
  
   Copy $File $WorkFile ; rename the file

    If Open(2, $WorkFile)=0
      
      $ = RedirectOutput($OutPutDir+$FileProcessed,1) ; output to output dir with original file-name
      $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
    EndIf
Next
?
?
? "Skrevet " $counter " filer til lagringsmappe " $OutPutDir ; Write confirmation of written files to output-dir

? "Loggfil 'Logfile.txt' ligger i mappen " $LogFile  ; Display the placement of the log-file
WriteLine(1 ,@crlf + $crlf + "Skrevet "+ $counter +" filer til lagringsmappe "+ $OutPutDir + @CRLF)  ; Same info written in the log-file
Close (1)
Sleep 15

_________________________
I was placed on earth to do a job. Right now I have so much to do, I will never die..