declan bright

A PowerShell Script for Copying Files with Find Replace

PowerShell

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.

Download

Parameters

The script takes several parameters.

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

Examples

(Parameters are shown on multiple lines for legibility.)

Example 1 - Basic example

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