具有相同的最后修改日期的groovy复制文件

use*_*379 7 directory groovy copy file

嗨我想将一个文件从一个目录复制到另一个目录,但日期必须相同.所以当fromdirectory中的最后修改日期是14:35时,我希望它在tod目录中是相同的.

我怎么能用groovy做到这一点?

Chr*_*orf 9

使用AntBuilder

new AntBuilder().copy ( file                 : 'path/to/source', 
                        tofile               : 'path/to/destination', 
                        preservelastmodified : 'true' )
Run Code Online (Sandbox Code Playgroud)

使用Java/Groovy File API

def source = new File ('path/to/source')
def destination = new File ('path/to/destination')

source.withInputStream { is -> 
  destination << is 
}

destination.lastModified = source.lastModified()
Run Code Online (Sandbox Code Playgroud)