Ok Jim, here's my big mama jama.
You saved my butt today. We have a DBA that likes to think he knows CF.
He's supposed to stay out of our source, but he doesn't so my boss said
write a checksum that does the whole app and makes sure he isn't making
changes.
Here's what I came up with. It takes about 30 seconds to parse 2000 files.
BTW I would welcome improvements to this, specifically in performance
issues.
<!--- get the list of files in the application --->
<cf_dp_filefind directory="C:\Inetpub\wwwroot\tim" recurse="Y"
extensionstofind="cfm" outputstyle="query" outputquery="files">
<!--- create the array that will contain the hashed file value, and the name
and path to the file --->
<cfset hashedArray = arrayNew(1)>
<!--- loop through the file list, hash the files content, write the hashed
value to the array and the name and path to the file --->
<cfloop query="files">
<cffile action="read" file="#file#" variable="thisFile">
<cfset hashedArray[files.currentRow] = hash(thisFile)>
</cfloop>
<!--- dump the array into the existing query object --->
<cfset temp = queryAddColumn(files, "fileHash", hashedArray)>
<!--- if the file already exists create a new file name --->
<cfif fileExists("c:\Inetpub\wwwroot\tim\baseLine.csv")>
<cfset myFileName = "checkSum#dateFormat(now(), "mmddyyyy")#.csv">
<cfelse>
<cfset myFileName = "baseLine.csv">
</cfif>
<!--- create the file with the hashed values in it --->
<cfset fileContent = "">
<cfoutput query="files">
<cfset fileContent = fileContent & files.fileHash & "," & files.file
& chr(13)>
</cfoutput>
<cffile action="write" file="c:\Inetpub\wwwroot\tim\#myFileName#"
output="#fileContent#">
<!--- perform file comparison --->
<!--- get the baseline file --->
<cfif not isDefined("server.baseline") or myFileName is "baseLine.csv">
<cffile action="read" file="c:\Inetpub\wwwroot\tim\baseLine.csv"
variable="server.baseline">
</cfif>
<!--- get the most current file --->
<cffile action="read" file="c:\Inetpub\wwwroot\tim\#myFileName#"
variable="currentHash">
<!--- now run a compare --->
<!--- get the lengths of the two files --->
<cfset baseLen = listLen(server.baseline, chr(13))>
<cfset newLen = listLen(currentHash, chr(13))>
<!--- first ensure that there are the same number of lines between the
baseline and the current file --->
<cfif baseLen neq newLen>
<cfset changesMade = 1>
<cfelse>
<cfset changesMade = 0>
</cfif>
<!--- now loop through both files and do a comparison of the hashed values
--->
<cfset thisFile = "">
<cfif not changesMade>
<cfloop from="1" to="#baseLen#" index="i">
<cfif listGetAt(listGetAt(server.baseLine, i, chr(13)), 1)
neq listGetAt(listGetAt(currentHash, i, chr(13)), 1)>
<cfset thisFile = listAppend(thisFile,
listGetAt(listGetAt(currentHash, i, chr(13)), 2))>
</cfif>
</cfloop>
</cfif>
<!--- inform the user that there are a different number of lines between the
two files --->
<cfif changesMade>
There are a different number of lines between the two files<br />
</cfif>
<!--- inform the user that the has values for these files do not match --->
<cfif len(trim(thisFile)) gt 0>
There have been changes made to the following files: <br />
<cfoutput>
<cfloop list='#thisFile#' index="i">
#i#<br />
</cfloop>
</cfoutput>
<cfelse>
No changes noted.
</cfif>
> -----Original Message-----
> From: Jim Davis [mailto:[EMAIL PROTECTED]
> Sent: Monday, July 17, 2006 1:05 PM
> To: CF-Community
> Subject: RE: Unique file extensions question
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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/cf_lists/message.cfm/forumid:5/messageid:211333
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:5
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.5