# CompareTrees[.mpw] # by Matej Horvat # Takes names of two directories (possibly relative to the current directory) # and recursively compares their contents. # This script MUST be placed in your Scripts folder or it won't be able to call # itself. If "{1}" == "" Or "{2}" == "" Or "{3}" <> "" Echo ¶# CompareTrees: Two directory names are required ³ Dev:StdErr Exit 1 End # Resolve directory names to full paths # and get the names of subdirectories of the first one # (those in the second one don't matter because we can only compare them # if they exist in both) Set PrevDir `Directory` Directory "{1}" ³ Dev:Null If {Status} <> 0 Echo ¶# CompareTrees: Directory `Quote "{1}"` doesn¶'t exist. ³ Dev:StdErr Exit 2 End If Set DirA `Directory` Set Subdirs "" For Item In Å If `Exists -d "{Item}"` Set Subdirs "{Subdirs} ¶"{Item}¶"" End End Directory "{PrevDir}" Directory "{2}" ³ Dev:Null If {Status} <> 0 Echo ¶# CompareTrees: Directory `Quote "{2}"` doesn¶'t exist. ³ Dev:StdErr Exit 2 End If Set DirB `Directory` Directory "{PrevDir}" Unset PrevDir # For each file in DirA, check whether it exists in DirB, # and if it does, check whether it is equal For F In `Files -s "{DirA}"` If "`Exists -f "{DirB}{F}"`" Equal -d -q "{DirA}{F}" "{DirB}{F}" If {Status} <> 0 Echo CompareFiles `Quote "{DirA}{F}" "{DirB}{F}"` End Else If "`Exists -d "{DirB}{F}"`" Echo ¶# `Quote "{DirA}{F}"` is a file while `Quote "{DirB}{F}"` is a directory Else Echo ¶# "{DirA}{F}" has no counterpart in "{DirB}" End End # For each file in DirB, check whether it exists in DirA For F In `Files -s "{DirB}"` If "`Exists -f "{DirA}{F}"`" # Nothing; we already compared files above Else If "`Exists -d "{DirA}{F}"`" Echo ¶# `Quote "{DirA}{F}"` is a directory while `Quote "{DirB}{F}"` is a file Else Echo ¶# {DirB}{F} has no counterpart in {DirA} End End # For each directory in DirA, check whether it exists in DirB, # and if it does, recursively compare them For D in {Subdirs} If "`Exists -d "{DirB}{D}"`" CompareTrees `Quote "{DirA}{D}" "{DirB}{D}"` End End