Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
content = Result
Set FSO = Nothing
Function Result
If FSO.FileExists(filename) Then
Result = LinesInFile(filename)
ElseIf FSO.FolderExists(filename) Then
Result = LinesInFolder(filename)
End If
End Function
Function LinesInFile(byVal pFile)
Dim OTF
On Error Resume Next
Set OTF = FSO.OpenTextFile(pFile, ForReading, False)
If Err.Number = 0 Then
OTF.ReadAll
LinesInFile = OTF.Line - 1
OTF.Close
Else
LinesInFile = 0
End If
On Error GoTo 0
Set OTF = Nothing
End Function
Function LinesInFolder(byVal pFolder)
Dim l, lf, lff
l = 0
On Error Resume Next
Set lff = FSO.GetFolder(pFolder)
If Err.Number = 0 Then
For Each lf In lff.Files
l = l + LinesInFile(lf)
Next
For Each lf In lff.SubFolders
l = l + LinesInFolder(lf)
Next
LinesInFolder = l
Else
LinesInFolder = 0
End If
Set lff = Nothing
End Function |