by Tom Bruinsma (4 Submissions)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (3 Votes)
Find and replace text strings in multiple files within a directory. This allows for wilcards. Please Vote if you like it! :)
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:\temp" '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