Jump to content

Recommended Posts

Posted (edited)

On XP.

How To Find data in text file and replace it?

I want Command Script in batch file or VBScripts---> .bat or .vbs

------------------------------------------------------

Example. Search Command "I Love You" in c:\Testt.txt

and replace "I Love You" it is "HACK BY ME"

and Search and replace "I Love You" in line 5 column 7

save and exit.

------------------------------------------------------

Help me Plz.

Edited by cr4ckerK9

Posted
Const FOR_READING = 1
Const FOR_WRITING = 2
Const vbTextCompare = 1 ' essentatially case insensitve
Const vbBinaryCompare = 0 ' case sensitve

vbOldText = "I Love You"
vbNewText = "HACK BY ME"

strFileName = "C:\scripts\test.txt"
strCheckForString = UCase("july")

Set objFS = CreateObject("Scripting.FileSystemObject")
Set objTS = objFS.OpenTextFile(strFileName, FOR_READING)
strContents = objTS.ReadAll
objTS.Close

NewText = Replace(strContents, vbOldText, vbNewText, 1, -1, vbTextCompare)

Set objTS = objFS.OpenTextFile(strFileName, FOR_WRITING)

objTS.Write NewText
objTS.Close

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...