Skip to content

Instantly share code, notes, and snippets.

@webdevwilson
Created January 19, 2011 15:55
Show Gist options
  • Save webdevwilson/786347 to your computer and use it in GitHub Desktop.
Save webdevwilson/786347 to your computer and use it in GitHub Desktop.
Groovy code to compare to directory trees and copy different files over
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