Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Line counter?

Status
Not open for further replies.

gbaughma

IS-IT--Management
Staff member
Nov 21, 2003
4,772
US
I have a rather large web site that I have developed; it includes both HTML (.htm) and ASP (.asp) pages.

Of course, it's in multiple directory levels below
Is there a simple way to find out how many LINES of code I've written over the past 9 years? In other words, a program or script that I can point at my and say "Count the lines in all .HTM and .ASP pages, including subdirectories, and tell me how many lines total there are".

Any thoughts?



Just my 2¢
-Cole's Law: Shredded cabbage

--Greg
 
I have a VBScript at home that does a recursive search of directories and subdirectories for files with certain specs that I use for backing up specific files I've modified.. If no one answers you about this before this evening, I'll try to remember to get it to you after I get home. Counting lines in a file would be a simple addition to the script and I'll add that in before I send it to you.

Lee
 
Greg, I couldn't get email to you, so here's the code for the line count script:

Code:
Option Explicit

Dim driveobj, fileset
Dim foldername, folderobj
Dim subfolders, linecount
Dim sourcedrive
Dim endmessage
Dim ForReading

sourcedrive="c"
foldername = "inetpub\[URL unfurl="true"]wwwroot\"[/URL]
ForReading = 1

sourcedrive=UCase(Left(sourcedrive,1)) & ":\"

Set driveobj=CreateObject("Scripting.FileSystemObject")
Set folderobj=driveobj.GetFolder(sourcedrive & foldername)
Set subfolders=folderobj.SubFolders
Set fileset=folderobj.Files

linecount = 0
DoCount subfolders, fileset, foldername

Set driveobj=Nothing
Set folderobj=Nothing
Set subfolders=Nothing
Set fileset=Nothing

endmessage = "Count Finished - " & linecount

MsgBox endmessage

'End of program


Sub DoCount(subfolder, files, foldername)

Dim onefolder, newfoldername
Dim onefile, fileset
Dim filename

'go to lowest subfolder first
For Each onefolder in subfolder
  newfoldername = LCase(foldername & onefolder.name & "\")
  Set folderobj=driveobj.GetFolder(sourcedrive & newfoldername)
  Set subfolders=folderobj.SubFolders
  Set fileset=folderobj.Files
  DoCount subfolders, fileset, newfoldername
Next

'if no more subfolders, then go through files
For Each onefile in files
  filename = LCase(sourcedrive & foldername & onefile.name)
  If Right(filename, 4) = ".asp" Then
    CountLines(filename)
  ElseIf Right(filename, 4) = ".htm" Then
    CountLines(filename)
  ElseIf Right(filename, 5) = ".html" Then
    CountLines(filename)
  End If
Next

Set folderobj=Nothing
Set subfolders=Nothing
Set fileset=Nothing

End Sub

Sub CountLines(onefilename)

Dim file, oneline

Set file = driveobj.OpenTextFile(onefilename, ForReading, False)
Do While file.AtEndOfStream <> True
  oneline = Trim(file.ReadLine)
  
  'Does not count blank lines
  If Len(oneline) > 0 Then
    linecount = linecount + 1
  End If
Loop

file.Close

End Sub

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top