robsuttonjr
MIS
I am using the following to search and replace text. Well it is actually creating a new file but it does what I need. Anyone know of a better way to say search and replace within a file without having to create a new file and not using memo's but directly editing the file?
The following is in a prg which I pass 4 parameters.
LPARAMETERS lcPath, lcFileName, lcSearchFor, lcReplaceWith
oFSO = CreateObject("Scripting.FileSystemObject")
oInFile = oFSO.OpenTextFile(lcPath+lcFileName)
oOutFile = oFSO.OpenTextFile(lcPath+"tmp"+lcFileName,2,.T.)
Do WHILE !oInFile.AtEndOfStream
oOutFile.WriteLine(STRTRAN(oInFile.Readline,lcSearchFor,lcReplaceWith))
ENDDO
oInFile.Close
oOutFile.Close
Forums rule, pass it on!!!
Rob
The following is in a prg which I pass 4 parameters.
LPARAMETERS lcPath, lcFileName, lcSearchFor, lcReplaceWith
oFSO = CreateObject("Scripting.FileSystemObject")
oInFile = oFSO.OpenTextFile(lcPath+lcFileName)
oOutFile = oFSO.OpenTextFile(lcPath+"tmp"+lcFileName,2,.T.)
Do WHILE !oInFile.AtEndOfStream
oOutFile.WriteLine(STRTRAN(oInFile.Readline,lcSearchFor,lcReplaceWith))
ENDDO
oInFile.Close
oOutFile.Close
Forums rule, pass it on!!!
Rob