Microsoft Small Basic

Program Listing: BRQ733
' Fifty - finds programs that have less equal 50 lines
' Copyright (c) 2012 Nonki Takahashi. All rights reserved.
'
CRLF = Text.GetCharacter(13) + Text.GetCharacter(10)

While "True"
TextWindow.Write("Path? ")
path = TextWindow.Read()
' The following line could be harmful and has been automatically commented.
' files = File.GetFiles(path)
num = Array.GetItemCount(files)
For i = 1 To num
If Text.EndsWith(files[i], ".smallbasic") Or Text.EndsWith(files[i], ".sb") Then
filename = files[i]
File_CountLines()
If lines <= 50 Then
TextWindow.WriteLine(lines + " " + filename)
EndIf
EndIf
EndFor
TextWindow.WriteLine("")
EndWhile

Sub File_CountLines
' param filename - file name
' return lines - lines of file
' The following line could be harmful and has been automatically commented.
' buf = File.ReadContents(filename)
len = Text.GetLength(buf)
ptr = 1
lines = 0
While ptr <= len
_ptr = Text.GetIndexOf(Text.GetSubTextToEnd(buf, ptr), CRLF)
If _ptr = 0 Then
_ptr = len + 1
EndIf
ptr = ptr + _ptr + 1
lines = lines + 1
EndWhile
EndSub