diff --git a/utils.go b/utils.go index c7faa5b..81bd858 100644 --- a/utils.go +++ b/utils.go @@ -2,6 +2,10 @@ package gismanager import ( "io/ioutil" + "os" + "path" + "path/filepath" + "strings" yaml "gopkg.in/yaml.v2" ) @@ -23,3 +27,43 @@ func FromConfig(configFile string) (config *ManagerConfig, err error) { config = &gpkgConfig return } +func isSupported(ext string) bool { + for _, a := range supportedEXT { + if a == ext { + return true + } + } + return false +} + +//GetGISFiles retrun List of All GIS Files in this path +func GetGISFiles(root string) ([]string, error) { + var files []string + fileInfo, statErr := os.Stat(root) + if statErr != nil { + return files, statErr + } + if !fileInfo.IsDir() { + files = append(files, fileInfo.Name()) + return files, nil + } + dirInfo, err := ioutil.ReadDir(root) + if err != nil { + return files, err + } + for _, file := range dirInfo { + if file.IsDir() { + subFiles, subErr := GetGISFiles(path.Join(root, file.Name())) + if subErr == nil { + files = append(files, subFiles...) + } + } else { + extension := strings.ToLower(filepath.Ext(file.Name())) + if isSupported(extension) { + files = append(files, file.Name()) + } + } + } + + return files, nil +} diff --git a/vars.go b/vars.go index 5031086..76b3920 100644 --- a/vars.go +++ b/vars.go @@ -3,6 +3,7 @@ package gismanager import "regexp" var pgRegex = regexp.MustCompile(`^\s?PG:\s?.*$`) +var supportedEXT = []string{".zip", ".json", ".geojson", ".gdb", "kml", ".shp"} const ( geopackageDriver = "GPKG"