Easy way to count total lines of code?
Easy way to count total lines of code?
How can I view how many lines of code my program has? For example if I am building a project that spans several include files?
▓▓▓▓▓▒▒▒▒▒░░░░░
Re: Easy way to count total lines of code?
Click on details when compiling!
But the project must be large to see the lines
But the project must be large to see the lines

Re: Easy way to count total lines of code?
If you put all your code in one folder (with subfolders) you can use this code:
Code: Select all
Procedure ExamineDirectoryRecursive(Path.s, Pattern.s, List _List.s())
Protected Dir = ExamineDirectory(#PB_Any, Path, Pattern)
If Dir
While NextDirectoryEntry(Dir)
AddElement(_List())
_List() = Path + DirectoryEntryName(Dir)
Wend
FinishDirectory(Dir)
EndIf
Dir = ExamineDirectory(#PB_Any, Path, "")
If Dir
While NextDirectoryEntry(Dir)
If DirectoryEntryType(Dir) = #PB_DirectoryEntry_Directory
If DirectoryEntryName(Dir) <> "." And DirectoryEntryName(Dir) <> ".." And FindString(DirectoryEntryName(Dir), "Examples", 0) = 0
ExamineDirectoryRecursive(Path + DirectoryEntryName(Dir) + "\", Pattern, _List())
EndIf
EndIf
Wend
FinishDirectory(Dir)
EndIf
EndProcedure
Dir.s = "C:\project\" ; use final \
NewList _List.s()
ExamineDirectoryRecursive(Dir, "*.pp", _List())
I = 0
ForEach _List()
;Debug _List()
ReadFile(0, _List())
N = I
While Not Eof(0)
I + 1
S.s = ReadString(0)
If Trim(s) = ""
Empty + 1
EndIf
Wend
Debug LSet(Str(I-N), 5) + _list() ;ReplaceString(_List(), Dir, "")
Next
Debug "Total lines: " + Str(I)
Debug "Non-empty lines: " + Str(I - Empty)
Debug "Empty lines: " + Str(Empty)
Re: Easy way to count total lines of code?

You mean to tell me there isn't a magic button I can press to get it? I guess writing a compiler tool for this would be an excellent learning experiment.

▓▓▓▓▓▒▒▒▒▒░░░░░
- Fluid Byte
- Addict
- Posts: 2336
- Joined: Fri Jul 21, 2006 4:41 am
- Location: Berlin, Germany
Re: Easy way to count total lines of code?
What's the point of counting the lines? Wanna' show off?
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Re: Easy way to count total lines of code?
Curiosity mainly. And trimming redundant code. And it would just be nice to know.Fluid Byte wrote:What's the point of counting the lines? Wanna' show off?
▓▓▓▓▓▒▒▒▒▒░░░░░
Re: Easy way to count total lines of code?
could it possible that you use the DEMO versionNituvious wrote:Curiosity mainly. And trimming redundant code. And it would just be nice to know.Fluid Byte wrote:What's the point of counting the lines? Wanna' show off?
and wanna avoid the Restrictions ?
SPAMINATOR NR.1
Re: Easy way to count total lines of code?
Would it matter? 

( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Re: Easy way to count total lines of code?
Type "pbcompiler yourfile.pb" and it will tell you the number of lines processed. If you include some file multiple times it will get counted multiple times, though.
Re: Easy way to count total lines of code?
Yes I use the demo version but it's not because I want to avoid the restriction. I haven't ever gotten close to the restriction before. I am simply curious how many lines of code I put into a project, that's all.Rings wrote:could it possible that you use the DEMO version
and wanna avoid the Restrictions ?
▓▓▓▓▓▒▒▒▒▒░░░░░
- Fluid Byte
- Addict
- Posts: 2336
- Joined: Fri Jul 21, 2006 4:41 am
- Location: Berlin, Germany
Re: Easy way to count total lines of code?
There's nothing illegal about reducing the number of lines anyway.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
Re: Easy way to count total lines of code?
Thank you!PB wrote:There's nothing illegal about reducing the number of lines anyway.

▓▓▓▓▓▒▒▒▒▒░░░░░
- Kwai chang caine
- Always Here
- Posts: 5494
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Re: Easy way to count total lines of code?
It's not for a project...but if that can help you ...
http://www.purebasic.fr/english/viewtop ... 60#p274560
http://www.purebasic.fr/english/viewtop ... 60#p274560

Not a destination
Re: Easy way to count total lines of code?
Hi Trond,
thanks for your edifying snippet
here are the actual results of the pb\example\sources codes-lines from the Linux edition
thanks for your edifying snippet

here are the actual results of the pb\example\sources codes-lines from the Linux edition

cheers ~ VeraTotal lines: 5644
Non-empty lines: 4266
Empty lines: 1378
Two growing code-collections: WinApi-Lib by RSBasic ~ LinuxAPI-Lib by Omi
Missing a download-file on the forums? ~ check out this backup page.
Missing a download-file on the forums? ~ check out this backup page.