Skip to content

Commit

Permalink
get list of supported files
Browse files Browse the repository at this point in the history
  • Loading branch information
hisham waleed karam committed Oct 6, 2018
1 parent 1085193 commit 3a720c9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
44 changes: 44 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package gismanager

import (
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"

yaml "gopkg.in/yaml.v2"
)
Expand All @@ -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
}
1 change: 1 addition & 0 deletions vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 3a720c9

Please sign in to comment.