does_exist.go (435B)
1 package rifs 2 3 import ( 4 "os" 5 ) 6 7 // DoesExist returns true if we can open the given file/path without error. We 8 // can't simply use `os.IsNotExist()` because we'll get a different error when 9 // the parent directory doesn't exist, and really the only important thing is if 10 // it exists *and* it's readable. 11 func DoesExist(filepath string) bool { 12 f, err := os.Open(filepath) 13 if err != nil { 14 return false 15 } 16 17 f.Close() 18 return true 19 }