mirror of
https://github.com/mudler/luet.git
synced 2025-09-04 16:50:50 +00:00
Add DirectoryIsEmpty
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -82,6 +83,20 @@ func ListDir(dir string) ([]string, error) {
|
||||
return content, err
|
||||
}
|
||||
|
||||
// DirectoryIsEmpty Checks wether the directory is empty or not
|
||||
func DirectoryIsEmpty(dir string) (bool, error) {
|
||||
f, err := os.Open(dir)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
if _, err = f.Readdirnames(1); err == io.EOF {
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// Touch creates an empty file
|
||||
func Touch(f string) error {
|
||||
_, err := os.Stat(f)
|
||||
|
Reference in New Issue
Block a user