Batch File to remove string in a text file

January 22, 2012 at 16:27:03
Specs: Windows XP, 2.0 GHz, 512MB
I need a script to remove this string "custombuttons-button353," from a file located here "C:\localstore.rdf.
I would appreciate any help.

Note: I hope no one becomes upset that I am posting the same question in the VB forum.

See More: Batch File to remove string in a text file

Report •

January 22, 2012 at 21:08:52
I posted this question differently on another forum and received a reply which worked pefectly

My question was answered by "PHV" on another forum here:


The question I asked there was a bit different than what I asked here but the answer is applicable.

My post on the other forum:

I have the "replace.vbs" file saved to C:\Windows.

I use it to find and replace strings in text files.

Command line Syntax:

replace.vbs OLDSTRING NEWSTRING C:\file.txt

How can I modify the replace.vbs script to delete the string rather than replace it with another string?

Dim FileName, Find, ReplaceWith, FileContents, dFileContents

Find = WScript.Arguments(0)

ReplaceWith = WScript.Arguments(1)

FileName = WScript.Arguments(2)

FileContents = GetFile(FileName)

dFileContents = replace(FileContents, Find, ReplaceWith, 1, -1, 1)

if dFileContents <> FileContents Then

WriteFile FileName, dFileContents

End If

function GetFile(FileName)

If FileName<>"" Then

Dim FS, FileStream

Set FS = CreateObject("Scripting.FileSystemObject")

on error resume Next

Set FileStream = FS.OpenTextFile(FileName)

GetFile = FileStream.ReadAll

End If

End Function

function WriteFile(FileName, Contents)

Dim OutStream, FS

on error resume Next

Set FS = CreateObject("Scripting.FileSystemObject")

Set OutStream = FS.OpenTextFile(FileName, 2, True)

OutStream.Write Contents

End Function

The reply which worked perfectly:

New PostPHV (MIS)

22 Jan 12 9:10

What happens if you use this command line ?
[b]replace.vbs OLDSTRING "" C:\file.txt[/b]


Report •

January 22, 2012 at 21:11:52
Typo should be "perfectly"

This is the correct link to the post:


Report •

Related Solutions

Ask Question