declan bright

A PowerShell Script for Copying Files with Find Replace


Copy-FilesReplaceString.ps1 is a utility script for copying files and performing a find & replace on the text within those files during the copy operation. The script can be used on its own or as part of a larger build script for copying code files and changing namespace declarations etc.



The script takes several parameters.

The path (relative or absolute) of the source directory.
The filter to be applied to the source when retrieving files
The path (relative or absolute) of the destination directory
The string value to find
The string value to replace


(Parameters are shown on multiple lines for legibility.)

Example 1 - Basic example

	-sourceDirectory "D:\Code\Shared\" 
	-filter "*.cs"
	-destinationDirectory "D:\Code\Project\" 
	-replaceStringFrom "namespace1"
	-replaceStringTo "namespace2"
View Comments