Gadgets: Calculates the current folder, how many lines of JS code and ASP code, and can also count how many bytes the code has

Source: Internet
Author: User
Tags constructor count printf split
js| Statistics

Calculates how many lines of JS code and ASP code are in the current folder, and how many bytes the code has to count

There are sample code

<%
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'\\
' \ from codeproject.com
' \ Calculate code
' \ Bluedestiny
' \ Mail:bluedestiny at 126.com
'\\
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Option Explicit
Response.buffer=false

Class Count_code
Private Fso,spath
Private Asplines, Jslines, Aspbytes, Jsbytes, aspwords
Private Sub Class_Initialize
' Constructor, create a new FSO instance
Set fso = CreateObject ("Scripting.FileSystemObject")
End Sub
Private Sub Class_Terminate
Set fso=nothing
End Sub
Private function iterate (path)
Dim folder, folders, files, file, ts, txt, arr, f
Set folder = Fso.getfolder (path)
Set files = Folder.files
Dim Rx, C
' Establish regular expressions,
' In fact, it should not be written here, it should be written in the constructor (including the variations used should be placed in the constructor),
' Because it's recursive, it's definitely less efficient to re-establish regular instances each time you call yourself. As few initialization values as possible in recursion
' I will not change, if you are interested, you need to change the friend
Set rx = new RegExp
Rx.ignorecase = True
Rx.global = True
Rx.pattern = "+"
' Recursive files for the current folder. Including JS and ASP
For each file in files
If Right (file.name,4) = ". asp" or right (file.name,3) = ". js" Then
Set ts = File.openastextstream
If Ts.atendofstream then txt = "" Else txt = ts.readall
Ts.close
txt = rx.replace (txt, "")
TXT = replace (TXT,VBCRLF&AMP;VBCRLF,VBCRLF)
arr = Split (replace (TXT,VBCRLF, ""), "")
Aspwords = aspwords + UBound (arr)
arr = Split (TXT,VBCRLF)
If Right (file.name,4) = ". asp" Then
Asplines = Asplines + UBound (arr)
Aspbytes = aspbytes + len (TXT)
Else
Jslines = Jslines + UBound (arr)
Jsbytes = jsbytes + len (TXT)
End If
End If
Next
' Recursively all subfolders of the current folder.
Set folders = Folder.subfolders
For each F in folders
Iterate F.path
Next
End Function

Public Property Let path (s)
Spath=server.mappath (s)
End Property
Public Sub Count
Iterate (spath)
End Sub
Public Sub printf
Response.Write "ASP:" & "<br/>"
Response.Write "Total Lines coded:" & asplines & "<br/>"
Response.Write "Total Bytes:" & Aspbytes & "" & "<br/>"
Response.Write "Total individual Elements (words) Typed:" & aspwords & "<br/>"
Response.Write "JScript:" & "<br/>"
Response.Write "Total Lines coded:" & jslines & "<br/>"
Response.Write "Total Bytes:" & Jsbytes
End Sub
End Class

'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
' \ Sample Code
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Dim o
Set O=new Count_code
O.path= "bluedestiny/"
O.count
o.printf
%>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.