Coldfusion Directory Compare

So I wrote this page to compare my many music directories to make figure out what is missing between the directories so I can sync them better. One problem I had was that if the file names were named differently it would determine them either missing or a new folder. If anyone else has any suggestions to make it better, please let me know.

view plain print about
1<cfsetting showdebugoutput="false" />
2<cfdirectory action="list" directory="\\ryan\Music" name="dirQuery" recurse="true" type="dir" listinfo="all" />
3<cfdirectory action="list" directory="Z:\My Music" name="dirQuery2" recurse="true" type="dir" listinfo="all" />
4
5<cfset Directory1Struct = {} />
6<cfset ProblemDirectory1 = {} />
7
8<cfloop query="dirQuery">
9    <cfif Directory EQ '\\ryan\Music'>
10        <cfset StructInsert(Directory1Struct,Name,{}) />
11    <cfelse>
12        <cfset ParentDirectory = ListGetAt(Directory,ListFindNoCase(Directory,'Music','\')+1,'\') />
13        <cfif NOT StructKeyExists(Directory1Struct[ParentDirectory],Name)>
14            <cfset StructInsert(Directory1Struct[ParentDirectory],Name,Name) />
15        <cfelse>
16            <cfif NOT StructKeyExists(ProblemDirectory1,ParentDirectory)>
17                <cfset StructInsert(ProblemDirectory1,ParentDirectory,{}) />
18                <cfset StructInsert(ProblemDirectory1[ParentDirectory],Name,Name) />
19            <cfelse>
20                <cfif NOT StructKeyExists(ProblemDirectory1[ParentDirectory],Name)>
21                    <cfset StructInsert(ProblemDirectory1[ParentDirectory],Name,Name) />
22                </cfif>
23            </cfif>
24        </cfif>
25    </cfif>
26</cfloop>
27
28<cfset Directory2Struct = {} />
29<cfset ProblemDirectory2 = {} />
30
31<cfloop query="dirQuery2">
32    <cfif Directory EQ '\\ryan\My Music'>
33        <cfset StructInsert(Directory2Struct,Name,{}) />
34    <cfelse>
35        <cfset ParentDirectory = ListGetAt(Directory,ListFindNoCase(Directory,'My Music','\')+1,'\') />
36        <cfif NOT StructKeyExists(Directory2Struct[ParentDirectory],Name)>
37            <cfset StructInsert(Directory2Struct[ParentDirectory],Name,Name) />
38        <cfelse>
39            <cfif NOT StructKeyExists(ProblemDirectory2,ParentDirectory)>
40                <cfset StructInsert(ProblemDirectory2,ParentDirectory,{}) />
41                <cfset StructInsert(ProblemDirectory2[ParentDirectory],Name,Name) />
42            <cfelse>
43                <cfif NOT StructKeyExists(ProblemDirectory2[ParentDirectory],Name)>
44                    <cfset StructInsert(ProblemDirectory2[ParentDirectory],Name,Name) />
45                </cfif>
46            </cfif>
47        </cfif>
48    </cfif>
49</cfloop>
50
51<cfset DifferenceStruct = {} />
52
53
54<cfloop collection="#Directory2Struct#" item="Artist">
55    <cfif StructKeyExists(Directory1Struct,Artist)>
56        <cfif isStruct(Directory2Struct[Artist])>
57            <cfloop collection="#Directory2Struct[Artist]#" item="Album">
58                <cfif NOT StructKeyExists(Directory1Struct[Artist],Album)>
59                    <cfif NOT StructKeyExists(DifferenceStruct,Artist)>
60                        <cfset StructInsert(DifferenceStruct,Artist,{}) />
61                        <cfset StructInsert(DifferenceStruct[Artist],Album,Album) />
62                    <cfelse>
63                        <cfset StructInsert(DifferenceStruct[Artist],Album,Album) />
64                    </cfif>
65                </cfif>
66            </cfloop>
67        </cfif>
68    </cfif>
69</cfloop>
70<cfdump var="#DifferenceStruct#"><cfabort>
71
72<cfdump var="#DirectoryStruct#" label="Directory Struct">
73<cfdump var="#ProblemDirectory#" label="Problem Struct">
74<cfabort>
75
76<cfset Directory1Listing = ListToArray(Replace(ValueList(dirQuery.name),"'","''","all")) />
77<cfset Directory2Listing = ListToArray(Replace(ValueList(dirQuery2.name),"'","''","all")) />
78
79<cfset MissingStruct = {} />
80<cfset Counter = 1 />
81<cfloop array="#Directory1Listing#" index="artist">
82    <cfif NOT ArrayFind(Directory2Listing,artist)>
83        <cfset StructInsert(MissingStruct,artist,artist) />
84    </cfif>
85</cfloop>
86<cfdump var="#MissingStruct#"><cfabort>

TweetBacks
Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Josh Knutson's Gravatar Do you think they have proper ID3 tags, if they do then you can use java methods to read the files in, and just look at their tagging information
# Posted By Josh Knutson | 2/25/10 5:45 PM
Ryan Vikander's Gravatar That's true, I just bored before a prod release and wanted to whip together a small app to do it. I will look into using the java method you speak of, but I am kinda doubtful they have proper tags. Most are crappy rips I did.
# Posted By Ryan Vikander | 2/25/10 5:50 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.6.004. Contact Blog Owner