On windows, I want to count the number of lines in all .py files in a directory and its…
- User
On windows, I want to count the number of lines in all .py files in a directory and its sub-directories, can you give me a command that does that?
Assistant
You can use this PowerShell command:
(Get-ChildItem -Path . -Filter "*.py" -Recurse | Get-Content | Measure-Object -Line).LinesOr if you prefer using the Command Prompt with
findstr:for /r %i in (*.py) do @type "%i" | find /c /v "" > nul && @echo %iBut the PowerShell version is cleaner and will give you the total count directly. If you want to see the count for each file individually as well as the total, you can use:
Get-ChildItem -Path . -Filter "*.py" -Recurse | ForEach-Object { $lines = (Get-Content $_.FullName | Measure-Object -Line).Lines Write-Host "$($_.Name): $lines lines" $lines } | Measure-Object -Sum | Select-Object -ExpandProperty SumThe first command is probably what you want - it will recursively find all .py files in the current directory and subdirectories and give you the total line count.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.