Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-sonnet-4-20250514· AnthropicHugging Face LMArena Human Preference 140K

On windows, I want to count the number of lines in all .py files in a directory and its…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with gpt-4.1-mini-2025-04-14’s answer.
  1. 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?

  2. Claude Assistant

    You can use this PowerShell command:

    (Get-ChildItem -Path . -Filter "*.py" -Recurse | Get-Content | Measure-Object -Line).Lines
    

    Or if you prefer using the Command Prompt with findstr:

    for /r %i in (*.py) do @type "%i" | find /c /v "" > nul && @echo %i
    

    But 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 Sum
    

    The 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.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.