Dont suppose anyone's written a...

R

Rob Meade

....little function for count lines of code?

I was going to do this a little while ago, hoping to count each line in each
file in each folder etc etc, and then determine whether it was say ASP, HTML
or comments....and give totals...

Anyone got anything like this they dont mind sharing?

Just curious...

Regards

Rob
 
B

Bob Barrows

Rob said:
...little function for count lines of code?

I was going to do this a little while ago, hoping to count each line
in each file in each folder etc etc, and then determine whether it
was say ASP, HTML or comments....and give totals...

Anyone got anything like this they dont mind sharing?

Just curious...

Regards

Rob

I haven't, but I can't foresee it taking more than five minutes using
FileSystemObject. Here are some resources:
http://www.aspfaq.com/filesystem.asp

HTH,
Bob Barrows
 
R

Rob Meade

...
I haven't, but I can't foresee it taking more than five minutes using
FileSystemObject. Here are some resources:

Hi Bob,

Thanks for the reply, I didn't think it would take long to do - but was
trying to be a bit lazy :)

If I get around to writing something I'll pop the code up here, incase
anyone else is interested (possibly not - hehe)

Rob
 
S

Steven Burn

Not sure if will work in ASP but for the line count, you could try something
along the line's of;

Dim FSO
Dim strFile
Dim strFiles
Dim strLine
Dim intCount

Set FSO = CreateObject("Scripting.FileSystemObject")
Set strFiles = FSO.GetFolder(Server.MapPath(./")).Files

For Each strFile in strFiles

Open StrFile For Input As #1
Do While Not EOF(1)
Line Input #, strLine
intCount = intCount +1
Loop
Close #1
response.Write strFile & " - " & intCount
Next

Set FSO = Nothing
Set strFile = Nothing
Set strFiles = Nothing
Set strLine = Nothing
set intCount = Nothing

--
Regards

Steven Burn
Ur I.T. Mate Group CEO
www.it-mate.co.uk

Disclaimer:
My advice is provided on an 'as-is' basis. Just because I tell you
something, does not mean I am right.
 
A

Aaron Bertrand [MVP]

This measures carriage returns and comments, not necessarily explicit lines
of code. You could loop through the split array to toss out empty lines or
comments, if you wanted to make it more sophisticated.

<%
folder = "<local folder path>" ' or server.mappath("/something/")
set fso = createobject("Scripting.FileSystemObject")
set fold = fso.getFolder(folder)
for each file in fold.files
if right(lcase(file.name), 4) = ".asp" then
set fs = fso.opentextfile(folder & file.name, 1)
lines = ubound(split(fs.readall(), vbCrLf)) + 1
response.write file.name & " : " & lines & " lines.<br>"
totalLines = totalLines + lines
fileCount = fileCount + 1
fs.close: set fs = nothing
end if
next
response.write "<p>Number of ASP files: " & fileCount
response.write "<p>Total lines in all ASP files: " & totalLines
set fold = nothing: set fso = nothing
%>

--
Aaron Bertrand, SQL Server MVP
http://www.aspfaq.com/

Please reply in the newsgroups, but if you absolutely
must reply via e-mail, please take out the TRASH.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top