Tutorial Count lines of code in a Visual Studio Project

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

Rake

Cesspool Admin
Administrator
Jan 21, 2014
11,574
78,998
2,317
How long you been coding/hacking?
5 years
To count the number of lines in a Visual Studio Solution or project, go to the root folder of that project and open a powershell prompt

For a C++ project you would do:
Code:
(gci -include *.cpp,*.h -recurse | select-string .).Count
For C# do:
Code:
(gci -include *.cs,*.xaml -recurse | select-string .).Count
Here's a git version too:

Bash:
git ls-files "*.h" "*.cpp" | xargs wc -l
I've merging all my code into one solution right now and rewriting it all, wow is it getting big. Today I was curious how big it has gotten.

I found this powershell query and my framework has 4601 lines of code! Holy hell that's alot of shitcode.

Run it on your biggest solution and post your result, would be neat to see how big other people's projects are
 
Last edited:

Rake

Cesspool Admin
Administrator
Jan 21, 2014
11,574
78,998
2,317
Here's a git version too:

git ls-files "*.h" "*.cpp" | xargs wc -l
 

Meow

Gimme food hooman.
Fleep Tier Donator
Nobleman
Apr 24, 2020
137
3,743
4
A small python script:

Python:
import sys
from pathlib import Path

files = list()
locAll = 0

for t in sys.argv[1:]:
    files += [f for f in Path("").rglob(f"*.{t}")]

if files:
    for f in files:
        try:
            loc = sum(1 for _ in open(f))
            locAll += loc
            print(f"[{f}] {loc} LOC")
        except:
            pass

    print(f"{locAll} lines of code")
python loc.py h cpp rc:
[AimbotRake\framework.h] 5 LOC
[AimbotRake\pch.h] 13 LOC
[AimbotRake\resource.h] 14 LOC
[AimbotRake\csgo.cpp] 153 LOC
[AimbotRake\dllmain.cpp] 47 LOC
[AimbotRake\pch.cpp] 5 LOC
[AimbotRake\AimbotRake.rc] 60 LOC
297 lines of code
 
  • Like
Reactions: Rake

iMoD1998

PPC Haxor
Trump Tier Donator
Dank Tier Donator
Full Member
Nobleman
Jul 10, 2020
66
3,668
3
You can also do this from within visual studio using this regex.

Code:
^(?([^\r\n])\s)*[^\s+?/]+[^\n]*$
Use like this:
1595857728077.png


Then click the dropdown and click find all.
1595857760980.png


1595857769205.png

and bobs your uncle.

Should work on 2013 and above.
 
  • Like
Reactions: Meow
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods League of Legends Accounts