計算行數
sub myonload()
Set fso = CreateObject("Scripting.FileSystemObject")
Set regEx = New RegExp ' Create a regular expression.
LineNum_max=0
end sub
sub go()
dim LineNum
ss= lcase(nFileType.value)
ThisCmd= "fileExt=""" & replace(ss, ",", """ or FileExt=""") & """"
' msgbox Thiscmd
' exit sub
ss= Lcase(nDirSkip.value)
ThisCmd2= "subDir=""" & replace(ss, ",", """ or SubDir=""") & """"
' msgbox thiscmd2: exit sub
path= path0.value
LineNum= 0
nn= HowmanyLineD(Path)
result.outerhtml= "<hr>[" & nn & "]" & path & "<div ID=result></div>"
nLineNum_max.innerText= LineNum_max
end sub
function HowmanyLineD(Path)
dim f, fc, nn_total , path0, objDir, objFile
Set f = fso.GetFolder(path)
nn_total=0
if DoSub.checked then
Set fc = f.SubFolders
for each objDir in fc
SubDir= Lcase(objDir.name)
'msgbox thiscmd2: exit function
path0= path & "\" & subDir
if not eval(thiscmd2) then
if subdir="att888" then msgbox subdir & eval(thiscmd2) : exit function
nn= HowmanyLineD(path0)
nn_total= nn_total+nn
result.outerhtml= "<li>[" & nn & "] [" & path0 & "]</li><div ID=result></div>"
else
result.outerhtml= "<li>[<font color=blue>skip</font>] [" & path0 & "]</li><div ID=result></div>"
end if
next
end if
Set colFiles = f.Files
For Each objFile in colFiles
file0= path & "\" & objfile.name
fileExt= Lcase(fso.GetExtensionName(file0))
if eval(thiscmd) then
nn= HowmanyLine(file0)
nn_total= nn_total+nn
result.outerhtml= "<li>[" & nn & "] " & file0 & "</li><div ID=result></div>"
else
result.outerhtml= "<li>[<font color=blue>skip</font>] " & file0 & "</li><div ID=result></div>"
end if
Next
HowmanyLineD= nn_total
end function
function HowmanyLine(file)
dim f, ss
regex.pattern="[\r\n]+"
regEx.IgnoreCase = True ' Set case insensitivity.
regEx.Global = True ' Set global applicability.
Set f = fso.OpenTextFile(file, ForReading)
ss=""
on error resume next
ss= f.readall()
on error goto 0
Set Matches = regEx.Execute(ss)
HowManyLine= Matches.count+1
if HowManyLine> LineNum_max then LineNum_max=HowmanyLine
f.close
end function
<body ID=MyBody onload=Myonload>
file type: <input type=text size=20 ID=nFileType value='asp,inc,asa'><br>
Directory:<input type=text size=50 ID=path0 value='c:\folder'><br>
<input type=checkbox ID=DoSub checked>sub directory<br>
Sub Directory to skip: <input type=text size=120 ID=nDirSkip value='Att888,StudentPostBuf,mymail,flowchart,notused,LSDoc'><br>
<button onclick=go>計算行數</button>