Ray Camden's Friday Puzzler - Compare Directories

Posted December 7, 2007 at 11:34 AM by Ben Nadel

Tags: ColdFusion

Ray Camden put up a Friday Puzzler to compare directories. This felt like a place to quickly throw some ColdFusion query of queries together. This solution will work with small directories, but certainly, I doubt that this will scale nicely as it would end up generating ENORMOUSLY SQL statements.

To start off with, I created two small directories:

Directory A:

  • \A\20071207.txt
  • \A\a-only.txt
  • \A\duplicate_file.txt

Directory B:

  • \B\20071207.txt
  • \B\b-only.txt
  • \B\duplicate_file.txt

Each directory has a file that is unique to them (a-only.txt and b-only.txt). Each on has a duplicate file (duplicate_file.txt). And, each on of them has a duplicate file that is a different size (20071207.txt). To compare these two directories from the directory, I ran this code:

  • <!--- Query files from directory A. --->
  • <cfdirectory
  • action="list"
  • directory="#ExpandPath( './A/' )#"
  • name="qA"
  • />
  •  
  •  
  • <!--- Query files from directory B. --->
  • <cfdirectory
  • action="list"
  • directory="#ExpandPath( './B/' )#"
  • name="qB"
  • />
  •  
  •  
  • <!--- Query for files that are in A, but not in B. --->
  • <cfquery name="qAOnly" dbtype="query">
  • SELECT
  • [name]
  • FROM
  • qA
  • WHERE
  • [type] = 'File'
  • AND
  • (
  • 1 = 1
  •  
  • <!---
  • Make sure the current A record does NOT
  • match any records in the B query.
  • --->
  • <cfloop query="qB">
  •  
  • AND
  • [name] != '#qB.name#'
  •  
  • </cfloop>
  • )
  • </cfquery>
  •  
  •  
  • <!--- Query for files that are in B, but not in B. --->
  • <cfquery name="qBOnly" dbtype="query">
  • SELECT
  • [name]
  • FROM
  • qB
  • WHERE
  • [type] = 'File'
  • AND
  • (
  • 1 = 1
  •  
  • <!---
  • Make sure the current B record does NOT
  • match any records in the A query.
  • --->
  • <cfloop query="qA">
  •  
  • AND
  • [name] != '#qA.name#'
  •  
  • </cfloop>
  • )
  • </cfquery>
  •  
  •  
  • <!---
  • Query for files that are both in A and B, but not
  • on the same date or size.
  • --->
  • <cfquery name="qBoth" dbtype="query">
  • SELECT
  • qA.[name]
  • FROM
  • qA,
  • qB
  • WHERE
  • qA.[type] = 'File'
  • AND
  • qA.[name] = qB.[name]
  • AND
  • (
  • qA.datelastmodified != qB.datelastmodified
  • OR
  • qA.size != qB.size
  • )
  • </cfquery>
  •  
  •  
  •  
  • <!--- Dump out results. --->
  • <cfdump
  • var="#qAOnly#"
  • label="Directory A Only"
  • />
  •  
  • <br />
  •  
  • <cfdump
  • var="#qBOnly#"
  • label="Directory B Only"
  • />
  •  
  • <br />
  •  
  • <cfdump
  • var="#qBoth#"
  • label="Both But Different"
  • />

When we run that, we get this CFDump output:


 
 
 

 
Directory Compare Using ColdFusion Query of Queries  
 
 
 

So, it works for small little directory compares. I know anything about File Diffs or Directory Diffs, so I am sure that there are way more optimized ways of doing this. But, ColdFusion query of queries makes this a rather easy task.




Reader Comments

Dec 7, 2007 at 4:41 PM // reply »
153 Comments

My solution also used QoQ, but differently:

http://www.coldfusionjedi.com/index.cfm/2007/12/7/Friday-Challenge--Compare-Directories#cB5E79338-19B9-E658-9D3917D4071BDB2D

-R


Dec 7, 2007 at 9:37 PM // reply »
6 Comments

Interesting approach. I requested the challenge since I have to write a script to see if previous people were doing their development on the development server or the production server :(

Here is a link to my original idea:
http://www.mediafire.com/?6yttt3x1kdt (download)
http://snippets.dzone.com/posts/show/4864 (view online)

Any thoughts on my solution would be appreciated.


Dec 10, 2007 at 8:01 AM // reply »
11,246 Comments

@Rick,

Your solution is very good. My hat is off to you, good sir. It's nice to see someone who really knows how to leverage ColdFusion query of queries. Sometimes I think they are one of the unsung heroes of ColdFusion.


Mar 21, 2008 at 12:18 PM // reply »
7 Comments

Thanks for the article, I was seeking it.


Mar 27, 2008 at 11:50 AM // reply »
1 Comments

"So you can find the information on it on my search resource
http://fileshunt.com"


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 25, 2013 at 10:01 PM
My Experience With AngularJS - The Super-heroic JavaScript MVW Framework
@Avi, Really glad to help! @Jaredwilli, I'm finding a this image hits home with a lot of people :) Hopefully we can all work through the rough patches together! @Prateek, AngularJS has error ... read »
May 25, 2013 at 9:53 PM
Nested Views, Routing, And Deep Linking With AngularJS
@Mrsean2k, I'm glad I could help! I haven't been able to keep up with the ui-router stuff. I keep saying that I'll carve out time, but I just haven't gotten to it :( ... read »
May 25, 2013 at 9:49 PM
What If All User Interface (UI) Data Came In Reports?
@Jonah, Thanks for the book recommendations. I am looking them up right now. I can see that Object Thinking is available for the Kindle App - sweet! Also, I just recently heard Martin Fowler on the ... read »
May 25, 2013 at 9:41 PM
HashKeyCopier - An AngularJS Utility Class For Merging Cached And Live Data
@Chris, I'm super excited to hear that my posts are helpful. I am also loving AngularJS; but, it definitely has some caveats and some odd behaviors and some things that just don't seem to "wor ... read »
May 25, 2013 at 9:36 PM
Ask Ben: Manually Enforcing Basic HTTP Authorization In ColdFusion
@Adam, @Jason, After reading these comments, I double-checked my latest implementation and I am happy to report that I am using listFirst() and listRest(). ... read »
May 25, 2013 at 9:31 PM
Using "//" And ".//" Expressions In XPath XML Search Directives In ColdFusion
@Daxesh, I am not sure I understand the question about the current node. If you already have a reference to the current node, why would you need to query for it? As for parent node, I believe that ... read »
May 25, 2013 at 10:08 AM
Using "//" And ".//" Expressions In XPath XML Search Directives In ColdFusion
@Ben, my question is that i want the current node with its tag and its parent node. i just want only that data. So, give me the solution for that. and remember solution is working on " xpath 1.0 ... read »
May 25, 2013 at 10:01 AM
Using "//" And ".//" Expressions In XPath XML Search Directives In ColdFusion
hey ben, i want get my current node tag and also want the root node tag withing. So, how can i fix it.. ! ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools