计算当前文件夹中,有多少行JS代码和ASP代码,并且还可统计代码有多少字节
有示例代码
1
2'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
3'\\\
4'\\\ 来自 codeproject.com
5'\\\ 计算js和asp代码
6'\\\ 修改 bluedestiny
7'\\\ mail:bluedestiny at 126.com
8'\\\
9'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
10
11option explicit
12response.buffer=false
13
14class COUNT_CODE
15private fso,spath
16private asplines, jslines, aspbytes, jsbytes, aspwords
17private sub class_initialize
18set fso = createobject("scripting.filesystemobject")
19end sub
20private sub class_terminate
21set fso=nothing
22end sub
23private function iterate(path)
24dim folder, folders, files, file, ts, txt, arr, f
25set folder = fso.getfolder(path)
26set files = folder.files
27dim rx, c
28set rx = new regexp
29rx.ignorecase = true
30rx.global = true
31rx.pattern = " +"
32for each file in files
33if right(file.name,4)=".asp" or right(file.name,3)=".js" then
34set ts = file.openastextstream
35if ts.atendofstream then txt = "" else txt = ts.readall
36ts.close
37txt = rx.replace(txt," ")
38txt = replace(txt,vbcrlf&vbcrlf,vbcrlf)
39arr = split(replace(txt,vbcrlf," ")," ")
40aspwords = aspwords + ubound(arr)
41arr = split(txt,vbcrlf)
42if right(file.name,4)=".asp" then
43asplines = asplines + ubound(arr)
44aspbytes = aspbytes + len(txt)
45else
46jslines = jslines + ubound(arr)
47jsbytes = jsbytes + len(txt)
48end if
49end if
50next
51set folders = folder.subfolders
52for each f in folders
53iterate f.path
54next
55end function
56
57public property let path(s)
58spath=server.mappath(s)
59end property
60public sub count
61iterate(spath)
62end sub
63public sub printf
64response.write "ASP:" & "
65"
66response.write "Total Lines Coded: " & asplines & "
67"
68response.write "Total Bytes: " & aspbytes & "" & "
69"
70response.write "Total Individual Elements (words) Typed: " & aspwords & "
71"
72response.write "JScript:" & "
73"
74response.write "Total Lines Coded: " & jslines & "
75"
76response.write "Total Bytes: " & jsbytes
77end sub
78end class
79
80'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
81'\\\示例代码
82'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
83
84dim o
85set o=new COUNT_CODE
86o.path="bluedestiny/"
87o.count
88o.printf