Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.39 KB | None | 0 0
  1. func getFiles(dirPath string) ([]string, error) {
  2.     // check if dirPath ends with "/"
  3.     if !strings.HasSuffix(dirPath, "/") {
  4.         dirPath += "/"
  5.     }
  6.  
  7.     files, err := ioutil.ReadDir(dirPath)
  8.     if err != nil {
  9.         return nil, err
  10.     }
  11.  
  12.     var fileNames []string
  13.  
  14.     for _, f := range files {
  15.         if f.IsDir() {
  16.             continue
  17.         }
  18.         fileNames = append(fileNames, f.Name())
  19.     }
  20.  
  21.     return fileNames, nil
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement