Tag Archives: Find and Replace

How to Count the Number of Source Lines of Code, Find and Replace Content in Multiple Files

Motivation:

  • You have a source code folder and want to know the number of source lines of code.
  • You want to find and replace a string with another string in multiple files.

Procedure:

  1. Right click Start icon, click on Command Prompt (Admin) or Windows Powershell (Admin)
  2. Assume that the source code folder location is C:\Users\admin\Downloads\test, type below commands and press Enter
cd C:\Users\admin\Downloads\test

3. Assume that the source code file extension is .py, type below commands and press Enter

type *.py | Measure-Object -line

SLOC

4. Assume that you want to find and replace “.flac” string with “.wav” string in all .cue files in the “E:\New Music\” directory, type below command, then press Enter.

Get-ChildItem "E:\New Music\" *.cue -recurse | ForEach { (Get-Content -Path $_.FullName).Replace(".flac", ".wav") | Set-Content -Path $_.FullName }