Click here to Skip to main content
15,886,661 members
Articles / Programming Languages / ASP
Article

Count your ASP/JS Code! (mini-article)

Rate me:
Please Sign up or sign in to vote.
4.33/5 (5 votes)
7 Dec 20021 min read 74.3K   39   8
Here is a quick utility that shows you how much code you've written in your web application. It serves no practical purpose other than to let you see how much work you've done.

Introduction

Have you ever worked on a project for so long that you've lost count of how much work you've actually put into it? I've been working on a universal website content management system with a full no-code-required setup system for about 8 months now, days, nights and weekends. And after a while it's nice to be able to give yourself a bit of a pat on the back from knowing how much effort you've put in. Yesterday, having lost "the zone", I whipped up this little utility to work out how much code I'd actually written. I'm not going to post the source code as a downloadable file because it's really just a single file with not a whole lot of code. So instead, I'll just paste a copy of it here. All you need to do to make it relevant for your project, is save it to a file in a temporary directory on your web server and change line 6 (iterate(server.mappath("/web_api"))) to point at the folder that contains all your code. Hey presto! There's a nice little summary of how much work you've done!

At the moment, it only counts ASP and JS files, so modify the code accordingly if you want to count other things. Blank lines are not considered when counting the code. You'll get a result formatted like my own result at the time of writing this article:

ASP:
  Total Lines Coded: 15540
  Total Bytes: 628957
  Total Individual Elements (words) Typed: 86189

JScript:
  Total Lines Coded: 4282
  Total Bytes: 155837

The code

VBScript
<%
option explicit
dim fso
set fso = createobject("scripting.filesystemobject")
dim asplines, jslines, aspbytes, jsbytes, aspwords
iterate(server.mappath("/web_api"))
response.write "ASP:
Total Lines Coded: " & asplines & "
Total Bytes: " & aspbytes & "
Total Individual Elements (words) Typed: " & aspwords
response.write "

JScript:
Total Lines Coded: " & jslines & "
" & "Total Bytes: " & jsbytes

function iterate(path)
    dim folder, folders, files, file, ts, txt, arr, f
    set folder = fso.getfolder(path)
    set files = folder.files
    dim rx, c
    set rx = new regexp
    rx.ignorecase = true
    rx.global = true
    rx.pattern = "  +"
    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&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
    set folders = folder.subfolders
    for each f in folders
        iterate f.path
    next
end function
%>

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Australia Australia
Web application developer, graphic designer, aspiring entrepreneur, snowboarder and electronic music afficianado.


Comments and Discussions

 
GeneralI am looking for a JSP.net project .Can you plase send a mini project. Pin
bbsthdthgf8-Aug-08 14:58
bbsthdthgf8-Aug-08 14:58 
GeneralStack Pin
Anonymous7-Jul-04 4:25
Anonymous7-Jul-04 4:25 
GeneralRe: Stack Pin
Nathan Ridley7-Jul-04 12:01
Nathan Ridley7-Jul-04 12:01 
GeneralRe: Stack Pin
RichardGrimmer10-Apr-06 2:13
RichardGrimmer10-Apr-06 2:13 
GeneralExcellent utility..very helpful... Pin
Anonymous29-Jan-04 14:23
Anonymous29-Jan-04 14:23 
GeneralExcellent utility..very helpful... Pin
Anonymous29-Jan-04 14:23
Anonymous29-Jan-04 14:23 
GeneralOne good use. Pin
DHornpout10-Dec-02 9:50
DHornpout10-Dec-02 9:50 
GeneralInteresting... Pin
Steve McLenithan8-Dec-02 17:02
Steve McLenithan8-Dec-02 17:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.