Over the last couple of days in my free time, I've been working on a
modification to the code you guys posted, so it won't count blank lines
and lines that were commented out. Here are the results.
It looks for these comment types:
<!--- --->
<!-- -->
/* */
It won't count single comment lines, nor sections of commented code.
Also, if you happen to have your end comment tag at the beginning of
another line of valid code, that line /will/ be counted. Do you guys
see any problems with this code (aside from the mutilation of line
wrapped email)?
<cfdirectory directory="C:\apache2\htdocs\test\testFolder" action="list"
name="mySite" filter="*" sort="directory" recurse="yes">
<cfset totalLines = 0>
<!---loop over all the files and filter on list of extensions--->
<cfloop query="mySite">
<cfif type eq "file">
<cfif listLen(name, '.') GT 1 AND "cfc,cfm,css,html,js"
CONTAINS listGetAt(name, 2, '.')>
<!---create an array of line items (parse by
ascii carriage return and output the name of the file--->
<cffile action="read" file="#directory#\#name#"
variable="curFile">
<cfset beginComments = "<!--|\/\*">
<cfset endComments = "-->|\*\/">
<cfset relevantLines = 0>
<cfset skipLine = 0>
<cfset skipMultiple = 0>
<cfloop list="#curFile#" index="curLine"
delimiters="#chr(13)##chr(10)#">
<cfif (ReFind(beginComments,curLine)
<!--- The start of a CFML or HTML comment --->
and
ReFind(endComments,curLine) <!--- The end of a CFML or HTML comment --->
and not
ReFind("[[:print:]]+(<!--)",curLine)) <!--- don't skip lines where the
comment is after some code --->
or not
ReFind("[[:graph:]]",curLine) <!--- skip blank lines --->
>
<!--- In this case, we found a
single commented line, so skip it --->
<cfset skipLine = 1>
<cfelseif ReFind("<!--",curLine) and not
ReFind("[[:graph:]]+(<!--)",curLine)>
<!--- In this case, we found the
beginning of a commented section of code --->
<cfset skipLine = 1> <!---
skip this line --->
<cfset skipMultiple = 1>
<!--- set a flag to keep skipping lines until I tell you to stop --->
<cfelseif not skipMultiple>
<!--- this is a normal line of
code --->
<cfset skipLine = 0>
</cfif>
<cfif skipMultiple>
<!--- We're in a commented
section of code --->
<cfif ReFind("-->",curLine)>
<!--- we found the end
of the comment --->
<cfif
ReFind("(-->)[[:blank:]]*[[:print:]]+",curLine)>
<!--- Don't skip
this line if there is other uncommented code on the line (after the end
comment tag) --->
<cfset skipLine
= 0>
</cfif>
<cfset skipMultiple = 0>
<!--- remove the 'skip lines' flag --->
</cfif>
</cfif>
<cfif not skipLine>
<cfset relevantLines =
relevantLines+1>
</cfif>
</cfloop>
<cfoutput>#name#<br /></cfoutput>
<!---add current file's line count to total--->
<cfset totalLines = totalLines + relevantLines>
</cfif>
</cfif>
</cfloop>
<!---output line count total--->
<cfoutput>#totalLines#</cfoutput>
-----------------
This transmission may contain information that is privileged, confidential
and/or exempt from disclosure under applicable law. If you are not the intended
recipient, you are hereby notified that any disclosure, copying, distribution,
or use of the information contained herein (including any reliance thereon) is
STRICTLY PROHIBITED. If you received this transmission in error, please
immediately contact the sender and destroy the material in its entirety,
whether in electronic or hard copy format. Thank you. A1.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four
times a year.
http://www.fusionauthority.com/quarterly
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:253311
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4