SyntaxBomb - Indie Coders

Languages & Coding => Blitz Code Archives => Miscellaneous => Topic started by: BlitzBot on June 29, 2017, 00:28:40

Title: [bb] BB Source Code Counter by King Dave [ 1+ years ago ]
Post by: BlitzBot on June 29, 2017, 00:28:40
Title : BB Source Code Counter
Author : King Dave
Posted : 1+ years ago

Description : Counts the number of lines in all .bb files under the apps directory (including sub directorys).

Displays the total lines of code and the total size in bytes of them.

It does NOT count backup bb files.


Code :
Code (blitzbasic) Select
Graphics 520,340,16,2

dir.Dir=New Dir
dirloc$=CurrentDir$()

Print "Counting lines..."
While dir<>Null
lis=ReadDir(dirloc$)
If Not lis Then RuntimeError "Failed to read the '"+dirloc$+"' directory"
filen$=NextFile(lis)
While filen$<>""
If KeyHit(1) Then End
Select FileType(dirloc$+filen$)
Case 1 If Right$(filen$,3)=".bb"
Size=Size+FileSize(dirloc$+filen$)
file=ReadFile(dirloc$+filen$)
While Not Eof(file)
txt$=ReadLine(file)
If txt$<>"" And Left$(txt$,1)<>";" Then Lines=Lines+1 Else Blanks=Blanks+1
Wend
CloseFile file
EndIf
Case 2 If filen$<>"." And filen$<>".."
ndir.Dir=New Dir
ndirloc$=dirloc$+filen$+""
EndIf
End Select
filen$=NextFile(lis)
Wend
CloseDir lis
Delete dir
dir.Dir=First Dir
Wend

Cls
Locate 0,0
Print "Lines of code: "+Lines
Print "Blank or comment lines: "+Blanks
Print "---"
Print "Total lines: "+(Lines+Blanks)
Print:Print
kb#=Float#(Size)/1024
mb#=Float#(Size)/1048576
Print "Total file size: "+Size+" bytes ("+Left$(kb#,Len(kb#)-4)+" kb / "+Left$(mb#,Len(mb#)-4)+" mb)"
Print:Print
Print "Press any key to close."
FlushKeys
WaitKey
End

Type Dir
Field loc$
End Type


Comments : none...