programing

파워셸을 사용하여 프로젝트에서 선 수 찾기

skycolor 2023. 7. 26. 21:45
반응형

파워셸을 사용하여 프로젝트에서 선 수 찾기

제가 가지고 있는 프로젝트의 모든 원본 파일에 있는 총 줄 수를 세는 방법을 찾고 있습니다.배관을 해봤어요.dir -r -name안으로measure-object -line내가 가지고 있는 파일의 수를 계산할 뿐입니다.

이거 대본 있는 사람?

Get-ChildItem -Filter "*.cs" -Recurse | Get-Content | Measure-Object -line

답변해주신 모든 분들께 감사드립니다.제가 이것을 실행하게 된 방법은

dir . -filter "*.cs" -Recurse -name | foreach{(GC $_).Count} | measure-object -sum

GC는 Get-Content의 별칭입니다.
Get-ChildItem의 dir 별칭

나는 조금 만료되었고 이 명령이 실제로 모든 c# 파일을 재귀적으로 측정한다는 것을 발견했습니다.

Get-ChildItem -Filter *.cs -Recurse | Get-Content | Measure-Object -Word -Line -Character

Get-ChildItem . -Include *.txt -Recurse | foreach {(Get-Content $_).Count}

별칭으로 약간 축약됨:

GCI . -Include *.txt -Recurse | foreach{(GC $_).Count}

다음과 유사한 결과를 제공합니다.

Lines Words               Characters              Property
----- -----               ----------              --------
   21
   40
   29
   15
  294
   13
   13
  107

편집: 하위 폴더를 반복하도록 수정되었습니다.

EDIT 2: Measure-Object 사용이 제거되었습니다.

dir **.txt -sysse | 전체 이름 선택,@{name="LineCount"; 식={@(get-content $.fullname).카운트 }}

파일 이름과 줄 수를 인쇄합니다.

Get-ChildItem -re -in "*.cs" |
Foreach-Object { 
    $fileStats = Get-Content $_.FullName | Measure-Object -line
    $linesInFile = $fileStats.Lines
    Write-Host "$_=$linesInFile" 
} 

저는 비슷한 것이 필요했기 때문에 이것이 제가 생각해 낸 것입니다.

하나의 파일 유형: GET-ChildItem -Recurse -Filter '*.cs' | 콘텐츠 가져오기 | 측정 - 객체 - 선

여러 파일 형식: GET-ChildItem -Recurse - '.cs', '.aspx', '*ascx' | 내용 가져오기 | 측정 - 개체 - 선 포함

코드의 카운트 라인(공백 라인 제외)*.c프로젝트 폴더의 파일을 재귀적으로

Get-ChildItem -Path \project-dir\src -Filter "*.c" -Recurse | ForEach-Object{(Select-String -Path $_ -Pattern .).Count} | Measure-Object -Sum


Count             : 14
Average           :
Sum               : 979
Maximum           :
Minimum           :
StandardDeviation :
Property          :

세어보세요No. of lines디렉토리 내의 파일:

GCI . -Include *.* -Recurse | foreach{(GC $_).Count}

세어보세요SUM of lines디렉토리 내의 파일:

GCI . -Include *.* -Recurse | foreach{(GC $_).Count} | measure-object -sum

언급URL : https://stackoverflow.com/questions/561327/find-the-number-of-lines-in-a-project-with-powershell

반응형