diff options
Diffstat (limited to 'reader')
-rw-r--r-- | reader/reader.go | 14 | ||||
-rw-r--r-- | reader/reader_test.go | 8 |
2 files changed, 22 insertions, 0 deletions
diff --git a/reader/reader.go b/reader/reader.go index 449b8ba..4b9c425 100644 --- a/reader/reader.go +++ b/reader/reader.go @@ -7,6 +7,7 @@ import ( "io" "io/ioutil" "log" + "path/filepath" "strings" "github.com/tealeg/xlsx" @@ -174,3 +175,16 @@ func Extract(dm string, ssheet string) ExtractedData { } return outer } + +//GetTargetFiles finds all xlsx and xlsm files in directory. +func GetTargetFiles(path string) ([]string, error) { + fullpath := strings.Join([]string{path, "*.xlsx"}, "") + output, err := filepath.Glob(fullpath) + if err != nil { + return nil, err + } + if output == nil { + return nil, fmt.Errorf("cannot find any xlsx files in %s\n", path) + } + return output, nil +} diff --git a/reader/reader_test.go b/reader/reader_test.go index 25c1c2a..33eea2e 100644 --- a/reader/reader_test.go +++ b/reader/reader_test.go @@ -134,3 +134,11 @@ func TestExtract(t *testing.T) { t.Errorf("Expected E26 in Another Sheet sheet to be Integer: - instead it is %s", d["Another Sheet"]["E26"].Value) } } + +func TestGetTargetFiles(t *testing.T) { + path := "/home/lemon/go/src/github.com/hammerheadlemon/datamaps-go/reader/testdata/" + _, err := GetTargetFiles(path) + if err != nil { + t.Error(err) + } +} |