Wednesday 11 March 2015

Replace text in .txt file through VBScript - Advance Application Packaging


Replacing some text in .txt file or any file through VBScript,


Function ReplacePrgPath(sFilePath,FND,REPL)
  Dim goFso
  Dim oGFile,oFile,sFileContent
  Set goFso = CreateObject("Scripting.FileSystemObject")
  Set oGFile = goFso.GetFile(sFilePath)
  Set oFile = oGFile.OpenAsTextStream(1, -2)
  sFileContent = oFile.ReadAll
  oFile.Close
  Set oFile = Nothing

  sFileContent = Replace(sFileContent, FND, REPL)


  Set oFile = oGFile.OpenAsTextStream(2, 0)

  Err.Clear
  oFile.Write sFileContent
  oFile.Close
  Set oFile = Nothing
  Set oGFile = Nothing
End Function

ReplacePrgPath sActionItem, "C:\",RDRIVE & "\"




sActionItem          IS FILE NAME with PATH
"C:\"                     IS TEXT TO BE REPLACE
RDRIVE & "\"    IS TEXT TO BE REPLACE WITH


Thank you for reading.

2 comments: