FAQ
Hi,

Just wondering why it's so hard to get the timestamp of the file
modification/access time by integer?

I assume calling struct method is slower than retrieving struct field
directly? I have a bunch of files needs to be compared by the access time /
modification time, so I don't want to create a "Time" object for them. (or
does the Stat function already create one for me?

I tried this way to get the mtime integer, but failed:

return info_i.Sys().(syscall.Stat_t).Mtime <
info_j.Sys().(syscall.Stat_t).Mtime

And it returns:

         info_i.Sys().(*syscall.Stat_t).Mtime undefined (type
*syscall.Stat_t has no field or method Mtime)

Since don't work too:

return info_i.Sys().Mtim.Sec < info_j.Sys().Mtim.Sec

How can I get this done?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • C9s at Aug 2, 2014 at 4:55 am
    I currently got this done by:

    return info_i.ModTime().UnixNano() < info_j.ModTime().UnixNano()

    Is there an efficient way to do this?


    On Saturday, August 2, 2014 12:38:53 PM UTC+8, c9s wrote:

    Hi,

    Just wondering why it's so hard to get the timestamp of the file
    modification/access time by integer?

    I assume calling struct method is slower than retrieving struct field
    directly? I have a bunch of files needs to be compared by the access time /
    modification time, so I don't want to create a "Time" object for them. (or
    does the Stat function already create one for me?

    I tried this way to get the mtime integer, but failed:

    return info_i.Sys().(syscall.Stat_t).Mtime <
    info_j.Sys().(syscall.Stat_t).Mtime

    And it returns:

    info_i.Sys().(*syscall.Stat_t).Mtime undefined (type
    *syscall.Stat_t has no field or method Mtime)

    Since don't work too:

    return info_i.Sys().Mtim.Sec < info_j.Sys().Mtim.Sec

    How can I get this done?
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • peterGo at Aug 2, 2014 at 8:26 am
    return info_i.ModTime().Before(info_j.ModTime())

    Peter
    On Saturday, August 2, 2014 12:55:23 AM UTC-4, c9s wrote:

    I currently got this done by:

    return info_i.ModTime().UnixNano() < info_j.ModTime().UnixNano()

    Is there an efficient way to do this?


    On Saturday, August 2, 2014 12:38:53 PM UTC+8, c9s wrote:

    Hi,

    Just wondering why it's so hard to get the timestamp of the file
    modification/access time by integer?

    I assume calling struct method is slower than retrieving struct field
    directly? I have a bunch of files needs to be compared by the access time /
    modification time, so I don't want to create a "Time" object for them. (or
    does the Stat function already create one for me?

    I tried this way to get the mtime integer, but failed:

    return info_i.Sys().(syscall.Stat_t).Mtime <
    info_j.Sys().(syscall.Stat_t).Mtime

    And it returns:

    info_i.Sys().(*syscall.Stat_t).Mtime undefined (type
    *syscall.Stat_t has no field or method Mtime)

    Since don't work too:

    return info_i.Sys().Mtim.Sec < info_j.Sys().Mtim.Sec

    How can I get this done?
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • C9s at Aug 2, 2014 at 4:59 am
    Gist: https://gist.github.com/c9s/4f41b5665567608ecb17

    I am also wondering the way to sort file with more concise expression...

    In perl, we usually do the sorting in one line:

          @files = sort { (stat($a))[9] <=> (stat($b))[9] } @files;

    but in Go, we have to write a lot of interface methods for the struct,
    that's about 10 lines of code.
    On Saturday, August 2, 2014 12:38:53 PM UTC+8, c9s wrote:

    Hi,

    Just wondering why it's so hard to get the timestamp of the file
    modification/access time by integer?

    I assume calling struct method is slower than retrieving struct field
    directly? I have a bunch of files needs to be compared by the access time /
    modification time, so I don't want to create a "Time" object for them. (or
    does the Stat function already create one for me?

    I tried this way to get the mtime integer, but failed:

    return info_i.Sys().(syscall.Stat_t).Mtime <
    info_j.Sys().(syscall.Stat_t).Mtime

    And it returns:

    info_i.Sys().(*syscall.Stat_t).Mtime undefined (type
    *syscall.Stat_t has no field or method Mtime)

    Since don't work too:

    return info_i.Sys().Mtim.Sec < info_j.Sys().Mtim.Sec

    How can I get this done?
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • peterGo at Aug 2, 2014 at 9:41 am
    Some of your code seemed to be unnecessary. For example,

    http://play.golang.org/p/oj_qiO9Qsz

    Peter
    On Saturday, August 2, 2014 12:59:13 AM UTC-4, c9s wrote:

    Gist: https://gist.github.com/c9s/4f41b5665567608ecb17

    I am also wondering the way to sort file with more concise expression...

    In perl, we usually do the sorting in one line:

    @files = sort { (stat($a))[9] <=> (stat($b))[9] } @files;

    but in Go, we have to write a lot of interface methods for the struct,
    that's about 10 lines of code.
    On Saturday, August 2, 2014 12:38:53 PM UTC+8, c9s wrote:

    Hi,

    Just wondering why it's so hard to get the timestamp of the file
    modification/access time by integer?

    I assume calling struct method is slower than retrieving struct field
    directly? I have a bunch of files needs to be compared by the access time /
    modification time, so I don't want to create a "Time" object for them. (or
    does the Stat function already create one for me?

    I tried this way to get the mtime integer, but failed:

    return info_i.Sys().(syscall.Stat_t).Mtime <
    info_j.Sys().(syscall.Stat_t).Mtime

    And it returns:

    info_i.Sys().(*syscall.Stat_t).Mtime undefined (type
    *syscall.Stat_t has no field or method Mtime)

    Since don't work too:

    return info_i.Sys().Mtim.Sec < info_j.Sys().Mtim.Sec

    How can I get this done?
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • peterGo at Aug 2, 2014 at 1:59 pm
    More of your code seems to be inefficient. For example, redundant calls to
    obtain file information. For example,

    http://play.golang.org/p/_jG7u4NzW7

    Peter
    On Saturday, August 2, 2014 5:41:38 AM UTC-4, peterGo wrote:

    Some of your code seemed to be unnecessary. For example,

    http://play.golang.org/p/oj_qiO9Qsz

    Peter
    On Saturday, August 2, 2014 12:59:13 AM UTC-4, c9s wrote:

    Gist: https://gist.github.com/c9s/4f41b5665567608ecb17

    I am also wondering the way to sort file with more concise expression...

    In perl, we usually do the sorting in one line:

    @files = sort { (stat($a))[9] <=> (stat($b))[9] } @files;

    but in Go, we have to write a lot of interface methods for the struct,
    that's about 10 lines of code.
    On Saturday, August 2, 2014 12:38:53 PM UTC+8, c9s wrote:

    Hi,

    Just wondering why it's so hard to get the timestamp of the file
    modification/access time by integer?

    I assume calling struct method is slower than retrieving struct field
    directly? I have a bunch of files needs to be compared by the access time /
    modification time, so I don't want to create a "Time" object for them. (or
    does the Stat function already create one for me?

    I tried this way to get the mtime integer, but failed:

    return info_i.Sys().(syscall.Stat_t).Mtime <
    info_j.Sys().(syscall.Stat_t).Mtime

    And it returns:

    info_i.Sys().(*syscall.Stat_t).Mtime undefined (type
    *syscall.Stat_t has no field or method Mtime)

    Since don't work too:

    return info_i.Sys().Mtim.Sec < info_j.Sys().Mtim.Sec

    How can I get this done?
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • peterGo at Aug 2, 2014 at 8:08 pm
    A tested version.

    http://play.golang.org/p/U5CGqtRxLC

    Peter
    On Saturday, August 2, 2014 9:59:03 AM UTC-4, peterGo wrote:

    More of your code seems to be inefficient. For example, redundant calls to
    obtain file information. For example,

    http://play.golang.org/p/_jG7u4NzW7

    Peter
    On Saturday, August 2, 2014 5:41:38 AM UTC-4, peterGo wrote:

    Some of your code seemed to be unnecessary. For example,

    http://play.golang.org/p/oj_qiO9Qsz

    Peter
    On Saturday, August 2, 2014 12:59:13 AM UTC-4, c9s wrote:

    Gist: https://gist.github.com/c9s/4f41b5665567608ecb17

    I am also wondering the way to sort file with more concise expression...

    In perl, we usually do the sorting in one line:

    @files = sort { (stat($a))[9] <=> (stat($b))[9] } @files;

    but in Go, we have to write a lot of interface methods for the struct,
    that's about 10 lines of code.
    On Saturday, August 2, 2014 12:38:53 PM UTC+8, c9s wrote:

    Hi,

    Just wondering why it's so hard to get the timestamp of the file
    modification/access time by integer?

    I assume calling struct method is slower than retrieving struct field
    directly? I have a bunch of files needs to be compared by the access time /
    modification time, so I don't want to create a "Time" object for them. (or
    does the Stat function already create one for me?

    I tried this way to get the mtime integer, but failed:

    return info_i.Sys().(syscall.Stat_t).Mtime <
    info_j.Sys().(syscall.Stat_t).Mtime

    And it returns:

    info_i.Sys().(*syscall.Stat_t).Mtime undefined (type
    *syscall.Stat_t has no field or method Mtime)

    Since don't work too:

    return info_i.Sys().Mtim.Sec < info_j.Sys().Mtim.Sec

    How can I get this done?
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedAug 2, '14 at 4:39a
activeAug 2, '14 at 8:08p
posts7
users2
websitegolang.org

2 users in discussion

peterGo: 4 posts C9s: 3 posts

People

Translate

site design / logo © 2022 Grokbase