Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

groovy copy files with same last modified date

Hi I want to copy a file from 1 directory to another, but the date has to be the same. so when the last modified date in the fromdirectory is 14:35, I want it to be the same in the todirectory.

How can I do this using groovy?

like image 947
user999379 Avatar asked Oct 24 '11 12:10

user999379


1 Answers

Using AntBuilder

new AntBuilder().copy ( file                 : 'path/to/source', 
                        tofile               : 'path/to/destination', 
                        preservelastmodified : 'true' )

Using 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()
like image 115
Christoph Metzendorf Avatar answered Oct 18 '22 09:10

Christoph Metzendorf