1

Is it possible to achieve the same effect of the Global Replace option in Visual Studio using a script ?

I need to perform some global replaces in a significant amount of files, at the present moment I am using MS Visual Studio to do a Find Replace in Files (Global Replace). Is it possible to achieve this using a script to run on a Windows machine? Will there be any implications or differences in the result using the proposed script as compared to the VS option?

I have long lost touch writing scripts hence might need some refreshers on this matter.

euqifar
  • 11
  • 2
  • Possible duplicate of [PowerShell Script to Find and Replace for all Files with a Specific Extension](https://stackoverflow.com/questions/2837785/powershell-script-to-find-and-replace-for-all-files-with-a-specific-extension) – Michael Freidgeim Apr 05 '18 at 12:15

1 Answers1

0

If you have PowerShell, it's pretty straighforward with Get-ChildItem and a script I wrote called Replace-FileString.ps1. This blog post gives an example:

http://www.wintellect.com/cs/blogs/jrobbins/archive/2012/12/10/automatically-updating-sln-files-to-vs-2012.aspx

Here's another example:

Get-ChildItem -path D:\Path -filter *.txt -recurse | Replace-FileString.ps1 -pattern 'find me' -replacement 'replace me' -overwrite

The above command would get all *.txt files in D:\Path (and subdirectories), and for each of the .txt files, it would replace the string "find me" (without quotes) with "replace me" (without quotes). The Replace-FileString.ps1 script's -overwrite parameter overwrites the original file with the file containing the replaced string.

Bill

Bill_Stewart
  • 22,916
  • 4
  • 51
  • 62