From 7ae7080824505b5aef83654c93196da89984a928 Mon Sep 17 00:00:00 2001 From: Iakov Davydov Date: Mon, 13 Nov 2017 14:46:31 +0100 Subject: [PATCH] FileExists check if a file exists --- fs/fs.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 +}