Hi All,
I have VB script which will update the first two letters of a file. This script is working fine but after updating the file, the file not getting updated automatically.
This file is the log file of an application. When i replace the first two characters, the application will shut down and this will be monitored on the log file.
Once i replace the word, the file is getting locked and its not getting updated and we are not able to find whether the application is shutdown or not?
Provided the script below.
'usage:
cscript replace.vbs Filename "StringToFind""stringToReplace" Option ExplicitDim fso,strFilename,strSearch,strReplace,objFile,oldContent,newContent 'strFilename=WScript.Arguments.Item(0)
strFilename="C:\Documents and
Settings\sultan\Desktop\NCB\IVRTest.txt"
'strSearch=WScript.Arguments.Item(1)
strSearch="2? "
'strReplace=WScript.Arguments.Item(2)
strReplace="00 "
'Does file exist?
Set fso=CreateObject("Scripting.FileSystemObject")
if fso.FileExists(strFilename)=false thenwscript.echo "file not found!"wscript.Quit
end if'Read file
set objFile=fso.OpenTextFile(strFilename,1)
oldContent=objFile.ReadAll'Write file'newContent=replace(oldContent,strSearch,strReplace,1,1,0)
newContent=replace(oldContent,strSearch,strReplace)
set objFile=fso.OpenTextFile(strFilename,2)
objFile.Write newContent
objFile.CloseNeed to know why the file not getting updated?
Note: When editing the file manually it is working perfectly.
Thanks and Regards
Riyas