FAQ
Can this be improved upon?

func isADirectory(path string) bool {
f, err := os.Open(path)
handleError(err)
stat, err := f.Stat()
handleError(err)
return stat.IsDir()
}

--
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/groups/opt_out.

Search Discussions

  • Jan Mercl at May 21, 2013 at 7:54 am

    On Tue, May 21, 2013 at 9:46 AM, Jon Renner wrote:
    Can this be improved upon?

    func isADirectory(path string) bool {
    f, err := os.Open(path)
    handleError(err)
    stat, err := f.Stat()
    handleError(err)
    return stat.IsDir()
    }
    Not tested:

    func isDir(pth string) (bool, error) {
             fi, err := os.Stat(pth)
             if err != nil {
                     return false, err
             }

             return fi.Mode.IsDir(), nil
    }

    -j

    --
    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/groups/opt_out.
  • Jon Renner at May 21, 2013 at 8:15 am
    You were missing some parens on the Mode, but otherwise it is perfect, it
    fixed my permissions error. Thanks!
    On Tuesday, May 21, 2013 3:54:13 PM UTC+8, Jan Mercl wrote:
    On Tue, May 21, 2013 at 9:46 AM, Jon Renner wrote:
    Can this be improved upon?

    func isADirectory(path string) bool {
    f, err := os.Open(path)
    handleError(err)
    stat, err := f.Stat()
    handleError(err)
    return stat.IsDir()
    }
    Not tested:

    func isDir(pth string) (bool, error) {
    fi, err := os.Stat(pth)
    if err != nil {
    return false, err
    }

    return fi.Mode.IsDir(), nil
    }

    -j
    --
    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/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMay 21, '13 at 7:46a
activeMay 21, '13 at 8:15a
posts3
users2
websitegolang.org

2 users in discussion

Jon Renner: 2 posts Jan Mercl: 1 post

People

Translate

site design / logo © 2022 Grokbase