Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract file properties in groovy?

I have gsp which has table and i need to display created date time and last modified time of each file which in drive.

I am not getting how to retrieve file properties.can any body answer me.

Advance thanks laxmi.P

like image 989
laxmi Avatar asked May 30 '11 07:05

laxmi


People also ask

What are groovy properties?

When a Groovy class definition declares a field without an access modifier, then a public setter/getter method pair and a private instance variable field is generated which is also known as "property" according to the JavaBeans specification.

How do I open a groovy file?

From the Tools Main menu select Groovy > Open Script or Recent Scripts. Select the Groovy file and click Open. This opens the selected file in the Groovy editor. Edit the Groovy script.


2 Answers

The result of file.lastModified() is a long we can use to construct a new Date object. We can apply formatting on the Date object. The formatting rules of SimpleDateFormat can be applied.

new File('.').eachFileRecurse { file ->
    println new Date(file.lastModified()).format('EEE MMM dd hh:mm:ss a yyyy')
}
like image 184
mrhaki Avatar answered Oct 14 '22 23:10

mrhaki


You probably want something like:

new File(path-to-your-directory).eachFileRecurse{file->
println file.lastModified()
}
like image 40
virtualeyes Avatar answered Oct 14 '22 22:10

virtualeyes