FindDataFiles returns a list of data files as a string array. If str is a comma-separated list of paths, it returns that list. If str is a single path that is not a directory, it returns that path. If str is a directory, it returns the files in it that have one of the extensions in ext.
(str string, ext []string)
| 64 | // of paths, it returns that list. If str is a single path that is not a directory, it returns that |
| 65 | // path. If str is a directory, it returns the files in it that have one of the extensions in ext. |
| 66 | func FindDataFiles(str string, ext []string) []string { |
| 67 | if len(str) == 0 { |
| 68 | return []string{} |
| 69 | } |
| 70 | |
| 71 | list := strings.Split(str, ",") |
| 72 | if len(list) == 1 && list[0] != "-" { |
| 73 | // make sure the file or directory exists, |
| 74 | // and recursively search for files if it's a directory |
| 75 | |
| 76 | fi, err := os.Stat(str) |
| 77 | if os.IsNotExist(err) { |
| 78 | glog.Errorf("File or directory does not exist: %s", str) |
| 79 | return []string{} |
| 80 | } |
| 81 | Check(err) |
| 82 | |
| 83 | if fi.IsDir() { |
| 84 | matchFn := func(f string) bool { |
| 85 | for _, e := range ext { |
| 86 | if strings.HasSuffix(f, e) { |
| 87 | return true |
| 88 | } |
| 89 | } |
| 90 | return false |
| 91 | } |
| 92 | list = FindFilesFunc(str, matchFn) |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | return list |
| 97 | } |
| 98 | |
| 99 | // ErrMissingDir is thrown by IsMissingOrEmptyDir if the given path is a |
| 100 | // missing or empty directory. |