if wscript.arguments.count <> 4 then usage sSourceFile=wscript.arguments(0) sDestFile=wscript.arguments(1) sTargetText=wscript.arguments(2) sReplacementText=wscript.arguments(3) sTest=ReplaceText(sSourceFile,sDestFile,sTargetText,sReplacementText) Function ReplaceText(sSourceFile,sDestFile,sTarget,sNewText) 'Replaces characters in file w/case insensitive matching. 'Can use same source and destination file. cForWriting = 2 cForReading = 1 set oFSrt=CreateObject("Scripting.FileSystemObject") if oFSrt.FileExists(sSourceFile) then 'Read lines of file into array aLines ix=0 set oSourcert=oFSrt.OpenTextFile(sSourceFile, cForReading) do while oSourcert.AtEndOfStream<>true sLinefta=oSourcert.ReadLine Redim Preserve aLines(ix) aLines(ix)=sLinefta ix=ix+1 loop Set oSourcert=Nothing 'Write New file if oFSrt.FileExists(sDestFile) then set oFilert=oFSrt.GetFile(sDestFile) set oStreamrt=oFilert.OpenAsTextStream(cForWriting) else set oStreamrt=oFSrt.CreateTextFile(sDestFile,True) end if for each sLine in aLines sNewLine=sLine if instr(1,sLine,sTarget,1) > 0 then sNewLine=replace(sLine,sTarget,sNewText,1,-1,1) end if oStreamrt.WriteLine (sNewLine) next else wscript.echo "File "&sSourceFile&" cannot be found." end if set oFilert=nothing set oStreamrt=Nothing set oFSrt=Nothing end Function Sub Usage wscript.echo "Usage:" wscript.echo wscript.echo "cscript ReplaceText.vbs SourceFile DestinationFile TargetText ReplacementText" wscript.echo wscript.echo "Source and destination files can be the same." wscript.echo wscript.quit end sub