replace text with vbs

Microsoft Windows xp pro with sp3 multil...
September 27, 2010 at 12:33:06
Specs: Windows XP
I want to replace text with vbs for any file with .txt extension in "c:\folder" path.
For example i have 20 file which 10 of them are .txt and have almost the same content, so i want to change to all of .txt files to replace "path" to something else like "path2"

I tried this but doesn't work it's saying bad file name or number:

Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("c:\path\*.txt", ForReading,, -1)

strText = objFile.ReadAll
strNewText = Replace(strText, "path", "path2")
strText = Replace(strNewText, "path3", "path")

Set objFile = objFSO.OpenTextFile("c:\path\*.txt", ForWriting, True, -1)
objFile.Write strText

See More: replace text with vbs

Report •

September 30, 2010 at 06:43:38
Set objFile = objFSO.OpenTextFile("c:\path\*.txt", ForReading,, -1)
OpenTextFile() opens one text file, not a group of text files. You need to iterate over every file in the folder, and open it if it's a text file.

Report •
Related Solutions

Ask Question