1
0
forked from MTSR/mapserver
mapserver/media/scan_recursive.go

62 lines
971 B
Go
Raw Normal View History

2019-06-14 11:57:29 +03:00
package media
import (
"os"
"path/filepath"
"strings"
)
// https://gist.github.com/mustafaydemir/c90db8fcefeb4eb89696e6ccb5b28685
func scan_recursive(dir_path string, ignore []string) ([]string, []string) {
folders := []string{}
files := []string{}
// Scan
filepath.Walk(dir_path, func(path string, f os.FileInfo, err error) error {
_continue := false
// Loop : Ignore Files & Folders
for _, i := range ignore {
// If ignored path
if strings.Index(path, i) != -1 {
// Continue
_continue = true
}
}
if _continue == false {
f, err = os.Stat(path)
// If no error
if err != nil {
2019-06-16 13:28:40 +03:00
return nil
2019-06-14 11:57:29 +03:00
}
// File & Folder Mode
f_mode := f.Mode()
// Is folder
if f_mode.IsDir() {
// Append to Folders Array
folders = append(folders, path)
// Is file
} else if f_mode.IsRegular() {
// Append to Files Array
files = append(files, path)
}
}
return nil
})
return folders, files
}