Batch Script - Find and replace text in multiple files in a directory

23,451

I've used this tool extensively to accomplish similar tasks: http://fart-it.sourceforge.net/ (Despite its name, it is a very handy tool).

For example, this command performs a search of all TXT files in the "C:\Dir\To\Files" (+subfolders) replacing all occurances of FOO with BAR. The -i switch performs a case-insensitive search.

FART -i -r "C:\Dir\To\Files\*.txt" FOO BAR
Share:
23,451
Guhan Murugesan
Author by

Guhan Murugesan

Updated on December 05, 2020

Comments

  • Guhan Murugesan
    Guhan Murugesan over 3 years

    I am new to writing batch scripts. I am in need of a simple batch file that searches for a text (eg., FOO) and replaces it with another text (eg., BAR) in all the text files within a folder and it's sub-folders.

    I need to give this batch file to the user. So, it is not possible to ask the user to install anything else. Can someone please help me with this?