github.com/oweisse/u-root@v0.0.0-20181109060735-d005ad25fef1/cmds/elvish/util/fullnames.go (about)

     1  package util
     2  
     3  import (
     4  	"os"
     5  	"sort"
     6  )
     7  
     8  // FullNames returns the full names of non-hidden files under a directory. The
     9  // directory name should end in a slash. If the directory cannot be listed, it
    10  // returns nil.
    11  //
    12  // The output should be the same as globbing dir + "*". It is used for testing
    13  // globbing.
    14  func FullNames(dir string) []string {
    15  	f, err := os.Open(dir)
    16  	if err != nil {
    17  		return nil
    18  	}
    19  
    20  	names, err := f.Readdirnames(-1)
    21  	f.Close()
    22  	if err != nil {
    23  		return nil
    24  	}
    25  
    26  	fullnames := make([]string, 0, len(names))
    27  	for _, name := range names {
    28  		if name[0] != '.' {
    29  			fullnames = append(fullnames, dir+name)
    30  		}
    31  	}
    32  
    33  	sort.Strings(fullnames)
    34  	return fullnames
    35  }