Browse Source

Merge pull request #7 from tendermint/develop

Develop
pull/1842/head
Ethan Buchman 8 years ago
committed by GitHub
parent
commit
6141dc6eed
1 changed files with 15 additions and 0 deletions
  1. +15
    -0
      os.go

+ 15
- 0
os.go View File

@ -3,6 +3,7 @@ package common
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"os" "os"
"os/signal" "os/signal"
@ -44,6 +45,20 @@ func EnsureDir(dir string, mode os.FileMode) error {
return nil 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 { func FileExists(filePath string) bool {
_, err := os.Stat(filePath) _, err := os.Stat(filePath)
return !os.IsNotExist(err) return !os.IsNotExist(err)


Loading…
Cancel
Save