Public Sub ReadDirTxt(DirPath As String)
Dim fso As Object
Dim fsod As Object
Dim fsof As Object
Dim f As Object
Dim i As Long
Dim s As String, fj() As String
Dim o As Long, o2 As Long
Dim m As Variant
Set fso = CreateObject("Scripting.FileSystemObject")
Set fsod = fso.getfolder(DirPath).Files
For Each f In fsod
If fso.GetExtensionName(f) = "txt" Then
o2 = o2 + 1
If f.Size > 0 Then
'文件为空的不处理
Set fsof = f.OpenAsTextStream(1)
s = fsof.ReadAll
fj = Split(s, vbCrLf)
For Each m In fj
If Len(m) > 0 Then
'空行不记
o = o + 1
End If
Next
End If
End If
Next
MsgBox "TXT文件数量:" & o2 & vbCrLf & "文件总行数:" & o
End Sub
---------------------------------
伸手党很让人烦。这个代码你慢慢琢磨吧。不解释。
调用:如:
Call ReadDirTxt("c:\windows")