Results 1 to 2 of 2

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

  1. #1
    Kenn is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    May 2012
    Posts
    1
    Reputation
    0

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

    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

  2. #2
    Paszt's Avatar
    Paszt is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2004
    Location
    Raleigh, NC - USA
    Posts
    1,502
    Reputation
    308
    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking