Wednesday, October 1, 2008

Find and Replace String in Files on Windows

.bat batch sample (Put the replace.exe in the same directory as this .bat file)

SET srcdir="C:\Documents and Settings\Desktop\test_replace"
SET findStr="DSN=Data_Source_Name_dev;"
SET replaceStr="DSN=Data_Source_Name;"
SET fileExtension="*.asp"

replace.exe -srcdir %srcdir% -find %findStr% -replace %replaceStr% -fname %fileExtension%
PAUSE



Description:
Replace is a Windows command line utility that searches files in directories to find a given text and replace with another. It can be incorporated in your scripts and invoked automatically. It can search files in nested directories. It can optionally copy modified files into another directory.

Bulk file Find/Replace tool version 1.0. Copyright 2005 - bestcode.com
This program finds a given string in a batch of files and replaces them with ano
ther string and places the output files in a separate directory if such director
y is specified. The file size must be small enough to fit in available memory.

Command line parameters are:

-srcdir adirectory directory of the original files. By default, this is t
he current directory.

-destdir adirectory destination directory to save modified files. By defau
lt, this is the current directory. The source files will be over written.

-find atext find this text to replace.

-replace atext replace the text that was found with this one.

-fname apattern the file name pattern to search, for example *.*

-casesens presense of this flag means search is case sensitive.

-quotes this flag means the following characters are used instead of double quo
tes in the -find and -replace parameters. This is to help escaping quotes inside
your find replace parameters.


Read more about Replace.exe Bulk File Text Replace tool here.

No comments: