Remove character/phrase inside multiple files

Hello,

I have the script below that will remove a character or phrase that is inside the " ".  What I would like to do is have it search the folder on all files and remove the character but inside the file, leave the first character alone (skip it) and remove the rest.

' Constants for I/O
Const ForReading = 1
Const ForWriting = 2

' Define folder to search
strBaseDir = "C:\test\"

' Access the folder
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strBaseDir)

' Process each file in the folder
For Each objFile in objFolder.Files
    ' Read the entire file
    strFile = objFile.Path
    Set objReader = objFSO.OpenTextFile(strFile, ForReading)
    strData = objReader.ReadAll
    objReader.Close

    ' Make desired replacements in the file
    strData = Replace(strData, " ? ", "")

    ' Write the updated data back to the file
    Set objWriter = objFSO.OpenTextFile(strFile, ForWriting, True)
    objWriter.Write strData
    objWriter.Close
Next

If the file was a .txt file and had the below data inside it,

?testdata?
this is a test?.

have the new file be

?testdata
this is a test.

Thank you.
cbonesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
This should handle that need.

' Constants for I/O
Const ForReading = 1
Const ForWriting = 2

' Define folder to search
strBaseDir = "C:\test\"

' Access the folder
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strBaseDir)

' Process each file in the folder
For Each objFile in objFolder.Files
    ' Read the entire file
    strFile = objFile.Path
    Set objReader = objFSO.OpenTextFile(strFile, ForReading)
    strData = objReader.ReadAll
    objReader.Close

    ' Make desired replacements in the file
    strData = Left(strData, 1) & Replace(Mid(strData, 2), "?", "")

    ' Write the updated data back to the file
    Set objWriter = objFSO.OpenTextFile(strFile, ForWriting, True)
    objWriter.Write strData
    objWriter.Close
Next

Open in new window

~bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.