Search for text in multiple files, replace text & save.

Kenn

New member
Joined
May 12, 2012
Messages
1
Programming Experience
Beginner
I am attempting to make a text editor with VB.net. I have a folder which contains hundreds of text files. I would like to search through all files simultaneously, for some text then replace the text with other text & save, & overwrite originals. I've got most of the basic structure done, but I would like some suggestions on searching for text in all files in a folder.
Thank you
Kenn
 
One way would be to:

Use the FileSystem.GetFiles Method (String, SearchOption, String[]) (Microsoft.VisualBasic.FileIO) to obtain a list of the files.
Loop through the list and
-Use the FileSystem.ReadAllText Method (String) (Microsoft.VisualBasic.FileIO) to read each file.
-Replace the text (using String.Replace).
-Use the FileSystem.WriteAllText Method (String, String, Boolean) (Microsoft.VisualBasic.FileIO) to write the text to the file.


FileSystem Class (Microsoft.VisualBasic.FileIO)
Troubleshooting: Reading from and Writing to Text Files (Visual Basic)


This isn't exactly what I would call a text editor.
 
Back
Top