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
<%
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
%>