package util import "os" // FileExists reports whether there is a regular file at path. A directory, a // device node or a socket gives false, and so does anything the process is not // allowed to look at, since from the caller's point of view there is no usable // file there either way. // // Symbolic links are followed, so a link pointing at a regular file gives true // and a link pointing at nothing gives false. func FileExists(path string) bool { info, err := os.Stat(path) if err != nil { return false } return info.Mode().IsRegular() } // DirExists reports whether there is a directory at path. As with FileExists, // anything that cannot be looked at gives false, and symbolic links are // followed. func DirExists(path string) bool { info, err := os.Stat(path) if err != nil { return false } return info.IsDir() }