Browse Source

Add ListFiles()

master
Yang Luo 2 years ago
parent
commit
a048074153
1 changed files with 21 additions and 1 deletions
  1. +21
    -1
      util/path.go

+ 21
- 1
util/path.go View File

@@ -1,6 +1,9 @@
package util

import "os"
import (
"io/ioutil"
"os"
)

func FileExist(path string) bool {
if _, err := os.Stat(path); os.IsNotExist(err) {
@@ -8,3 +11,20 @@ func FileExist(path string) bool {
}
return true
}

func ListFiles(path string) []string {
res := []string{}

files, err := ioutil.ReadDir(path)
if err != nil {
panic(err)
}

for _, f := range files {
if !f.IsDir() {
res = append(res, f.Name())
}
}

return res
}

Loading…
Cancel
Save