简体   繁体   中英

Count lines all file and store to file in Windows cmd

I used this command to count lines of each file in a directory:

for %G in (*.java) do find /c /v "_+_" %G

But the result shows file's names are all uppercase. How can I prevent it? Then, How can I save the result to a file?

find seems to convert file names to upper-case. You could use input redirection to avoid find to output anything and use set /P to return the original file name without case conversion and without trailing line-break, so the returned count is appended to the file name (separated by : ):

set /P ="%~G: " < nul & find /C /V "" < "%~G"

To output the result to a file use output redirection :

(for %G in ("*.java") do @(set /P ="%~G: " < nul & find /C /V "" < "%~G")) > "output.txt"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM