diff --git a/fs/fs.go b/fs/fs.go index e339ed222..a96bff041 100644 --- a/fs/fs.go +++ b/fs/fs.go @@ -733,3 +733,16 @@ func CheckClose(c io.Closer, err *error) { *err = cerr } } + +// FileExists returns true if a file remote exists. +// If remote is a directory, FileExists returns false. +func FileExists(fs Fs, remote string) (bool, error) { + _, err := fs.NewObject(remote) + if err != nil { + if err == ErrorObjectNotFound || err == ErrorNotAFile { + return false, nil + } + return false, err + } + return true, nil +}