mercredi 27 décembre 2017

How to update line dynamically in VBScript?

I am writing a script, and I wanted to know how I can read a txt file and find the line and then replace it.

For example, if I have a txt file called ImportParms.txt which has some parameter lines in it that look like this:

cmdFile=E:\Jobs\UPCS\Parms\ImportParms.upcs_cmd
Process=StandardImport
LogFile=e:\JOBS\UPCS\Logs\ImportLog.txt
File=E:\jobs\UPCS\TestImportFile.txt
ImportRejects=No
RenameToOld=No
RenameDateStamp=No
ResultsReport="Public Reports\ImportResult"
LinkExisting=Custom1

I want to update the line that says File=something.txt every time it runs. So that instead of having

sCmd = sBotCmd & " file=""" & sUtilOut &""" " 

it will just say

sCmd = sBotCmd

From the part of my code that runs the exe which looks like this:

' Run processbot to update
Set oFile = oFSO.GetFile(sUtilOut)
if oFile.Size <> 0 then
   strFile=sWORK & "\parms\" & BOTPARMFILE
   Set objFile = objFS.OpenTextFile(strFile)
   Do Until objFile.AtEndOfStream
       strLine= objFile.ReadLine
       'if first for characters = "file" 
           'delete this line
           strFile.Write "file=" & sUtilOut
       'end if
   Loop
   objFile.Close 

   sBotCmd = """"& sWORK & "\" & BOTPROG & """ " _
             & " cmdFile=""" & sWORK & "\parms\" & BOTPARMFILE & """ "

   sCmd = sBotCmd
   Call OutMsg(isVerbose, isVerbose, sSysLog, _
              "Command: " & sCmd)
   iRetC = oShell.Run(sCmd,0,TRUE)
   Call OutMsg(isVerbose, isVerbose, sSysLog, _
              "RC: " & iRetC)
   If iRetC <> 0 Then 
            Call OutMsg(isVerbose, isVerbose, sSysLog, "Exiting with code "_ 
            & rcPROCBOT)
            wscript.quit(rcPROCBOT)
   end if
end if

Aucun commentaire:

Enregistrer un commentaire