Count lines of code in a directory windows
That's why I said He didn't specify how many files are there. My version is easier to remember, but Shin's version is better if You have more than a few files. I'm voting it up. Here we go: find. To find by file extension, use -name : find. Functionally, this works perfectly, but on large listing linux source it is really slow because it's starting a wc process for each file instead of 1 wc process for all the files.
I timed it at 31 seconds using this method compared to 1. That said, this faster method at least on OS X , ends up printing "total" several times so some additional filtering is required to get a proper total I posted details in my answer.
This has the benefit of working for an unlimited number of files. Well done! DougRichardson, you could consider this instead: find. If all you're interested in is the total, then you could go a bit further and use tail : find. So [h c cpp php cc] ends up being the same as [hcp ]. This works under Cygwin. For windows, LocMetrics do the job — Camille. A repeat of the accepted answer though posted at the same time.
Lines in each file: find. Paul Draper Paul Draper Joel Ellis Joel Ellis 1, 8 8 silver badges 26 26 bronze badges. No, Nathan. The xargs answers won't necessarily print the count as a single number. It may just print a bunch of subtotals. What about newlines? If your file names contain new lines, I'd say you have bigger problems. Also the -print is redundant, since it's implied in the absence of other actions.
Show 1 more comment. Here you go: find. I did find. The -- is to mark the end of options it's a bit unnecessary here. If I do 'find. None of the answers so far gets at the problem of filenames with spaces. It also restricts the exec to files only skipping directories : find. Gene Gene Can you enhance this to omit comments? I don't think the comment section is intended for condescending back and forth. Really, it's an honest question. Being able to do this kind of thing on your own in less time than it takes to get someone else on SO to do it for you is definitely a skill someone who aspires to be a software engineer should have.
I'm not condescending. If you figure this out yourself, you'll be ahead. I like this one! WC -L? Znik Znik 11 11 silver badges 14 14 bronze badges. I know it. In practice only last line can be incomplete because it hasn't got EOL.
Idea is counting all lines including incomplete one. It is very frequent mistake, counting only complete lines. This is answer why, and recipe how to do it properly. Who cares about the last line? Especially given all the empty lines inside the files. There are various measurement parameters are available. For example, Average, Count, sum, maximum, minimum, and more.
You can do many things with this code. Do it with concentration and patience. Check your alls steps and again and all codes or scripts. If you find any error you can contact us anytime via comment or better via email, We are always here to help you.
We hope that you liked this article. While your answer is helpful and accepted by the OP, it doesn't correctly answer OP's question. However on Win7 with PowerShell 2. EG: if you have a folder of sub folders, containing the desired files, but no files in the folder you start from and use the powershell recurse command it returns 0 and never tries to descend the folder chain.
Show 3 more comments. Only works with one extension, soon as I add another I get 0 lines — jjxtra. Jack Barker Jack Barker 41 3 3 bronze badges. One way would be with cloc Download the release exe Add the folder its in to the path e.
For getting a joint report of all subfolders cloc. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. However, I found out that this information is not available in Remote Development. The idea is to collect the information once in the local environment and store it so that it can be used remotely.
You can also change the location where your configurations are stored. However, you must carry the stored information to the remote environment by yourself.
Sign in. Get it now.
0コメント