Skip to content

Commit

Permalink
Merge pull request #7 from tendermint/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ebuchman committed Mar 3, 2017
2 parents e289af5 + 959efd3 commit 6141dc6
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions os.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package common
import (
"bufio"
"fmt"
"io"
"io/ioutil"
"os"
"os/signal"
Expand Down Expand Up @@ -44,6 +45,20 @@ func EnsureDir(dir string, mode os.FileMode) error {
return nil
}

func IsDirEmpty(name string) (bool, error) {
f, err := os.Open(name)
if err != nil {
return true, err //folder is non-existent
}
defer f.Close()

_, err = f.Readdirnames(1) // Or f.Readdir(1)
if err == io.EOF {
return true, nil
}
return false, err // Either not empty or error, suits both cases
}

func FileExists(filePath string) bool {
_, err := os.Stat(filePath)
return !os.IsNotExist(err)
Expand Down

0 comments on commit 6141dc6

Please sign in to comment.