Search Tools Links Login

Find and Replace in multiple files


Visual Basic 6, or VB Classic

Find and replace text strings in multiple files within a directory. This allows for wilcards. Please Vote if you like it! :)

Original Author: Tom Bruinsma

Code

Dim strFind As String
Dim strReplace As String
Dim strDestination As String
Dim strSource As String
Dim strFilter

strFind = "Hello" 'What to find
strReplace = "Goodbye" 'What to replace it with
strDestination = "c: emp" 'Where to put the files once they have been modified
strSource = "c:output" 'Where to get the files
strFilter = "*.txt" 'wildcards
'verification complete
Dim parse As String
Dim hold As String
'FIND AND REPLACE
sdir = Dir(strSource & "" & fMainForm.txtIncludeFilter)
Do While sdir <> ""
Open fMainForm.txtSource & "" & sdir For Input As #1
Do While Not EOF(1)
Line Input #1, parse
hold = hold & Replace(parse, fMainForm.txtReplace, fMainForm.txtFind)
Loop

Loop
Open fMainForm.txtSource & "" & sdir For Output As #1
Print #1, hold
Close #1
hold = ""
parse = ""
sdir = Dir()
Loop

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 100 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.