How Big Is Your Current Project?

Miscellaneous Forums/General Discussion/How Big Is Your Current Project?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Heres a blitzmax version of yans code, that now handles sub folders :)
Strict

Local dropped$ = Lower$(RequestDir("Choose a directory...","c:/program files/blitzmax"))

If FileType(dropped$) <> 2 Then RuntimeError "'" + dropped$ + "' is Not a directory"

Global total_c = 0
Global total_b = 0
Global total_r = 0
Global bb_file = 0

Type TFolder

	Global List:TList = CreateList()
	Field Link:TLink = ListAddLast(List,Self)
	Field Path$
	
EndType




Local Folder:TFolder = New TFolder
Folder.Path$ = dropped$

Repeat

	Folder = TFolder(TFolder.List.First())
	ScanDir(Folder.Path)
	RemoveLink(Folder.Link)

Until TFolder.List.Count()=0





Function ScanDir(dropped$)

	Local dir = ReadDir(dropped$)
	Local file$ = NextFile$(dir)
	
	Local code = 0
	Local blank = 0
	Local comments = 0
	Local in:TStream
	Local l$

	While file$ <> ""
	
		code = 0
		blank = 0
		comments = 0
		
		If Lower$(Right$(file$, 3)) = ".bb" And FileType(dropped$ + "" + file$)=1
			bb_file = bb_file + 1
			
			in = OpenFile(dropped$ + "" + file$)
			If (Not in) Then RuntimeError "Couldn't open '" + file$ + "'"
			
			While (Not Eof(in))
				l$ = Left$(Trim$(ReadLine$(in)), 1)
				Select l$
					Case ""		; blank = blank + 1
					Case ";"	; comments = comments + 1
					Default		; code = code + 1
				End Select
			Wend		
			
			CloseFile in
			
			Print file$ + " = " + code + " Lines : " + blank + " Blank : " + comments + " Comments"
			
		ElseIf Lower$(Right$(file$, 4)) = ".bmx" And FileType(dropped$ + "" + file$)=1
			bb_file = bb_file + 1
			
			in = OpenFile(dropped$ + "" + file$)
			If (Not in) Then RuntimeError "Couldn't open '" + file$ + "'"
			
			While (Not Eof(in))
				l$ = Left$(Trim$(ReadLine$(in)), 1)
				Select l$
					Case ""		; blank = blank + 1
					Case "'"	; comments = comments + 1
					Default		; code = code + 1
				End Select
			Wend		
			
			CloseFile in
			
			Print file$ + " = " + code + " Lines : " + blank + " Blank : " + comments + " Comments"
			
		ElseIf FileType(dropped$ + "" + file$)=2 And file<>"." And file<>".."
		
			Local NewFolder:TFolder = New TFolder
			NewFolder.Path$ = dropped$ + "" + file$
			
		EndIf	

		total_c = total_c + code
		total_b = total_b + blank
		total_r = total_r + comments
		
		file$ = NextFile$(dir)
		
	Wend
	
EndFunction


Print
Print "Total Files : " + bb_file
Print "Total Lines : " + (total_c + total_b + total_r)
Print "Total Code  : " + total_c

WaitKey()