Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the number of lines in a project with powershell

Tags:

powershell

I'm trying to find a way to count the total number of lines in all of the source files of a project I have. I've tried piping dir -r -name into measure-object -line, but that just counts the number of files I have.

Does anyone have a script to do this?

like image 854
Dan Monego Avatar asked Feb 18 '09 14:02

Dan Monego


People also ask

How do I count lines of code in PowerShell?

The first one is to get the content of the files ( Get-Content ) and count the lines in there. With the Select-String cmdlet, you can count your code lines in a file or script using PowerShell. You can find more about Select-String on Microsoft Docs.

How do I do a carriage return in PowerShell?

The backtick character (`) represents an escape character in Powershell. An escape character lets us print otherwise unprintable characters to the standard output. The purpose of escape characters is to represent whitespace characters like: \t (tab), \n (newline), and \r (carriage return).

What is RN in PowerShell?

On output, PowerShell uses the platform-native newline sequence: `r`n on Windows, `n on Unix-like platforms. This applies to use of text-file-creating cmdlets, which comprise: Cmdlets for plain-text file creation: Set-Content and Out-File / redirection operator > .


1 Answers

Get-ChildItem -Filter "*.cs" -Recurse | Get-Content | Measure-Object -line 
like image 133
2 revs Avatar answered Sep 20 '22 07:09

2 revs