Groups
Groups
Sign in
Groups
Groups
golang-nuts
Conversations
About
Send feedback
Help
The best way to check if File is a directory?
103 views
Skip to first unread message
Jon Renner
unread,
May 21, 2013, 3:46:24 AM
5/21/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golan...@googlegroups.com
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()
}
Jan Mercl
unread,
May 21, 2013, 3:54:13 AM
5/21/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Jon Renner, golang-nuts
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
Jon Renner
unread,
May 21, 2013, 4:15:35 AM
5/21/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golan...@googlegroups.com, Jon Renner
You were missing some parens on the Mode, but otherwise it is perfect, it fixed my permissions error. Thanks!
Reply all
Reply to author
Forward
0 new messages