开发者

How to extract file properties in groovy?

开发者 https://www.devze.com 2023-03-09 17:36 出处:网络
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 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


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')
}


You probably want something like:

new File(path-to-your-directory).eachFileRecurse{file->
println file.lastModified()
}


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"
    }
} 
0

精彩评论

暂无评论...
验证码 换一张
取 消