Hi folks
Create test file on path with content.
Test file edit data-Trupti to Jethva
Data -Trupti
Save file c:\test.txt
Now write function as
Public function fnModifytextfile(strfilepath,strchangedata)
Const ForReading=1
Const ForWriting=2
Set objfso=createobject(“scripting.filesystemobject”)
Set myfile=objfso.opentextfile(strfilepath,forreading,true)
Set mytemp=objfso.opentextfile(strfilepath & “.tmp”, forwriting,true)
Do while not myfile.atendofstream
Myline=myfile.readline
If instr(myline,”Data”) then
Orignaldata=split(myline,”-“)
Orignaldatachange=orignaldata(1)
Datatobechange=“ “& strchangedata
Myline=replace(myline,orignaldatachange,datatobechange)
Endif
Mytemp. Writeline myline
Loop
Myfile.close
Mytemp.close
Objfso.deletefile(strfilepath )
Objfso.movefile strfilepath & “.tmp”, strfilepath
Msgbox “done”
End function
Call fnModifytextfile(“c:\test.txt”,”jethva”)
Create test file on path with content.
Test file edit data-Trupti to Jethva
Data -Trupti
Save file c:\test.txt
Now write function as
Public function fnModifytextfile(strfilepath,strchangedata)
Const ForReading=1
Const ForWriting=2
Set objfso=createobject(“scripting.filesystemobject”)
Set myfile=objfso.opentextfile(strfilepath,forreading,true)
Set mytemp=objfso.opentextfile(strfilepath & “.tmp”, forwriting,true)
Do while not myfile.atendofstream
Myline=myfile.readline
If instr(myline,”Data”) then
Orignaldata=split(myline,”-“)
Orignaldatachange=orignaldata(1)
Datatobechange=“ “& strchangedata
Myline=replace(myline,orignaldatachange,datatobechange)
Endif
Mytemp. Writeline myline
Loop
Myfile.close
Mytemp.close
Objfso.deletefile(strfilepath )
Objfso.movefile strfilepath & “.tmp”, strfilepath
Msgbox “done”
End function
Call fnModifytextfile(“c:\test.txt”,”jethva”)