What is the windows equivalent of Linux command wc -l?

后端 未结 3 774
粉色の甜心
粉色の甜心 2021-01-06 05:50

I have a piece of code that is meant to send the following to the linux command line:

wc -l C:/inputdirectory/P*

However, I need

3条回答
  •  余生分开走
    2021-01-06 06:20

    How can I count the lines in a set of files?

    Use the following batch file (CountLines.cmd):

    @echo off
    Setlocal EnableDelayedExpansion
    for /f "usebackq" %%a in (`dir /b %1`)  do (
      for /f "usebackq" %%b in (`type %%a ^| find "" /v /c`) do (
        set /a lines += %%b
        )
      )
    echo %lines%
    endlocal
    

    Usage:

    CountLines C:/inputdirectory/P*
    

    Further Reading

    • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
    • dir - Display a list of files and subfolders.
    • find - Search for a text string in a file & display all the lines where it is found.
    • for /f - Loop command against the results of another command.

提交回复
热议问题