Just use the "include" task property to specify the exact files from the directories you need to copy, something like this:
task copyDirectory(type: Copy) { from "/path/to/" include 'test-*/' into "/target" }
Update: if you want to copy the contents of directories only, you will have to deal with each file separately, something like this:
task copyDirectory(type: Copy) { from "/path/to/" include 'test-*/' into "/target" eachFile { def segments = it.getRelativePath().getSegments() as List it.setPath(segments.tail().join("/")) return it } includeEmptyDirs = false }
Stanislav
source share