Google Groups

Re: [go-nuts] path.Exists

Caleb Spare Mar 17, 2014 4:14 PM
Posted in group: golang-nuts
This has been discussed before a few times. I think the conclusion is
that it's not actually needed very often and that using os.Stat is
easy enough for the cases where it is required.

Note that newcomers often feel that they need an os.Exists function
before learning of a better way to do what they're trying to do. For
instance: if you are going to open the file, there's no reason to
check whether it exists first. The file could disappear in between
checking and opening, and anyway you'll need to check the os.Open
error regardless. So you simply call os.IsNotExist(err) after you try
to open the file, and deal with its non-existence there (if that
requires special handling).


On Mon, Mar 17, 2014 at 4:09 PM, Andrei Simionescu
<> wrote:
> I think a method path.Exists(path string) bool would be a nice thing to have
> – newbies like me will probably find this snippet of code [0] and implement
> the same helper method, anyway.
> Pros: Makes the language more newbie-friendly, thus potentially increasing
> adoption
> Cons: ??
> I can imagine language adoption being low on the priority list, but I don't
> see how adding this would hurt. Opinions?
> Thanks (and sorry if this has been discussed before)
> 0:
> --
> 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
> For more options, visit