Created
January 19, 2011 15:55
-
-
Save webdevwilson/786347 to your computer and use it in GitHub Desktop.
Groovy code to compare to directory trees and copy different files over
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def path1 = new File(args[0]).absolutePath | |
def path2 = new File(args[1]).absolutePath | |
def different = compareDirs(path1, path2) | |
different.files.each { | |
println it.from | |
new AntBuilder().copy ( file: it.from.absolutePath, tofile : it.to.absolutePath ) | |
} | |
println different.files.size() + ' of ' + different.count | |
def compareDirs(path1, path2) { | |
def different = [] | |
def count = 0; | |
def dir = new File(path1) | |
def dir2 = new File(path2) | |
dir.listFiles().each { | |
def filePath = it.absolutePath | |
if( !filePath.matches('.+\\.svn.+') ) { | |
def compare = new File(dir2.absolutePath + java.io.File.separator + it.name) | |
if( it.isDirectory() ) { | |
def dirResults = compareDirs(it.absolutePath, compare.absolutePath) | |
different += dirResults.files | |
count += dirResults.count | |
} else { | |
count++ | |
if( !compare.exists() || !it.text.equals(compare.text) ) { | |
different << [ from: it, to: compare ] | |
} | |
} | |
} | |
} | |
return [ files: different, count: count ] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment