mapserver/media/scan_recursive.go
2019-06-17 07:12:31 +02:00

62 lines
971 B
Go

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 {
return nil
}
// 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
}