I've been trying to get my head around with GoLang for few days and I am trying to make simple program which matches to certain files in certain directory. However I don't know how to pass variable to filepath.Glob function.
My attempt:
func ReadDirectory(srcDir string) {
files, _ := filepath.Glob("[a-Z0-9]")
fmt.Println(files)
}
This one prints well current directory where I am running the program. However I am looking for a way to list pass srcDir variable to it so I can find files from whatever directory.
Just prefix the pattern with the directory:
files, _ := filepath.Glob(srcDir + "/[a-Z0-9]")
The docs give this example:
The pattern may describe hierarchical names such as
/usr/*/bin/ed
(assuming the Separator is/
).