Reputation: 865
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
Upvotes: 14
Views: 13765
Reputation: 3592
To get access to properties not supported by the Java File API we can parse the output of a 'dir' or 'ls' command:
def file = 'sample.txt'
def cmd = ['cmd', '/c', 'dir', file, '/tc'].execute()
cmd.in.eachLine { line ->
if (line.contains(file)) {
def created = line.split()[0]
println "$file is created on $created"
}
}
Upvotes: 4
Reputation: 3592
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')
}
Upvotes: 15
Reputation: 11237
You probably want something like:
new File(path-to-your-directory).eachFileRecurse{file->
println file.lastModified()
}
Upvotes: 5