Click here to Skip to main content
14,176,276 members
Click here to Skip to main content
Add your own
alternative version


38 bookmarked
Posted 7 Dec 2002

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

, 7 Dec 2002
Rate this:
Please Sign up or sign in to vote.
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.


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:

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

  Total Lines Coded: 4282
  Total Bytes: 155837

The code

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

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 = true
    rx.pattern = "  +"
    for each file in files
        if right(,4)=".asp" or right(,3)=".js" then
            set ts = file.openastextstream
            if ts.atendofstream then txt = "" else txt = ts.readall
            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(,4)=".asp" then
                asplines = asplines + ubound(arr)
                aspbytes = aspbytes + len(txt)
                jslines = jslines + ubound(arr)
                jsbytes = jsbytes + len(txt)
            end if
        end if
    set folders = folder.subfolders
    for each f in folders
        iterate f.path
end function


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


About the Author

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

You may also be interested in...


Comments and Discussions

GeneralI am looking for a project .Can you plase send a mini project. Pin
bbsthdthgf8-Aug-08 14:58
memberbbsthdthgf8-Aug-08 14:58 
GeneralStack Pin
Anonymous7-Jul-04 4:25
memberAnonymous7-Jul-04 4:25 
GeneralRe: Stack Pin
Nathan Ridley7-Jul-04 12:01
memberNathan Ridley7-Jul-04 12:01 
GeneralRe: Stack Pin
RichardGrimmer10-Apr-06 2:13
memberRichardGrimmer10-Apr-06 2:13 
GeneralExcellent utility..very helpful... Pin
Anonymous29-Jan-04 14:23
memberAnonymous29-Jan-04 14:23 
GeneralExcellent utility..very helpful... Pin
Anonymous29-Jan-04 14:23
memberAnonymous29-Jan-04 14:23 
GeneralOne good use. Pin
DHornpout10-Dec-02 9:50
memberDHornpout10-Dec-02 9:50 
GeneralInteresting... Pin
Steve McLenithan8-Dec-02 17:02
memberSteve 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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04 | 2.8.190525.1 | Last Updated 8 Dec 2002
Article Copyright 2002 by Nathan Ridley
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid