Dont suppose anyone's written a...

Discussion in 'ASP General' started by Rob Meade, Nov 2, 2003.

  1. Rob Meade

    Rob Meade Guest

    ....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
    Rob Meade, Nov 2, 2003
    #1
    1. Advertising

  2. Rob Meade

    Bob Barrows Guest

    Rob Meade wrote:
    > ...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

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
    Bob Barrows, Nov 2, 2003
    #2
    1. Advertising

  3. Rob Meade

    Rob Meade Guest

    "Bob Barrows" wrote...

    > 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
    Rob Meade, Nov 2, 2003
    #3
  4. Rob Meade

    Steven Burn Guest

    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.


    Rob Meade <> wrote in message
    news:s47pb.3689$...
    > ...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
    >
    >
    Steven Burn, Nov 2, 2003
    #4
  5. 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.


    "Rob Meade" <> wrote in message
    news:s47pb.3689$...
    > ...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
    >
    >
    Aaron Bertrand [MVP], Nov 2, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve C. Orr, MCSD
    Replies:
    1
    Views:
    542
    reaway lee
    Aug 24, 2003
  2. Dan
    Replies:
    5
    Views:
    437
    Dan Poincelot
    Nov 16, 2004
  3. =?Utf-8?B?cm9kY2hhcg==?=

    don't suppose...

    =?Utf-8?B?cm9kY2hhcg==?=, Nov 21, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    415
    =?Utf-8?B?cm9kY2hhcg==?=
    Nov 22, 2005
  4. -
    Replies:
    1
    Views:
    326
    Esmond Pitt
    Jul 5, 2005
  5. KaiWen
    Replies:
    102
    Views:
    2,621
    Jorgen Grahn
    Sep 15, 2011
Loading...

Share This Page