Lev

|
Posted: Thu Apr 21, 2011 20:25 Post subject: |
|
|
Попробуй так:
Code: | 'запуск - wscript "диск:\путь\h_cpp_counter.vbs"
'параметры - %P%N
Dim stringscount, emptystrings, count_a, ccount_e,ccount,hcount_e,hcount
Set FSO = CreateObject("Scripting.FileSystemObject")
FF = WScript.Arguments(0)
Set re = New RegExp
re.Global=True
re.Multiline = True
re.Pattern="^\s*?$"
If FSO.FileExists(FF) Then
FileProc ff
Else
FolderProc ff
End If
MsgBox ff & vbCrLf & _
"-----" & vbCrLf & _
"строк в *.h файлах - " & hcount & vbCrLf & _
"непустых строк в *.h файлах - " & hcount-hcount_e & vbCrLf & _
"строк в *.cpp файлах - " & ccount & vbCrLf & _
"непустых строк в *.cpp файлах - " & ccount-ccount_e & vbCrLf & _
"-----" & vbCrLf & _
"всего строк - " & count_a
Sub FolderProc(fPath)
Dim loF
Set loF = FSO.GetFolder(fPath)
For Each F In loF.SubFolders
F = F.Path
FolderProc F
Next
For Each F In loF.Files
F = F.Path
FileProc F
Next
Set loF = Nothing
End Sub
Sub FileProc(f)
Select Case LCase(FSO.GetExtensionName(f))
Case "h"
count(f)
hcount=hcount + stringscount
hcount_e=hcount_e + emptystrings
count_a=count_a + stringscount
Case "cpp"
count(f)
ccount=ccount + stringscount
ccount_e=ccount_e + emptystrings
count_a=count_a + stringscount
End Select
End Sub
Sub count(f)
If fso.GetFile(f).Size Then
t=FSO.OpenTextFile(f).ReadAll
stringscount = UBound(Split(t, vbNewLine)) + 1
emptystrings=re.Execute(t).Count - stringscount + 1
End If
End Sub |
|
|