I'm having an issue with ioutils.ReadDir, for some reason it's scanning for all files in the project root instead of in the current directory only.
./main.go
import (
"myfolder/myfile"
)
func main() {
myfile.MyFunction()
}
./myfolder/myfile.go
package myfile
func MyFunction() {
files, err := ioutil.ReadDir(".")
if err != nil {
log.Fatal(err)
}
for _, f := range files {
fi, err := os.Stat(f.Name())
if err != nil {
log.Fatal(err)
return
}
switch mode := fi.Mode(); {
case mode.IsDir():
fmt.Printf("%#s is a folder
", f.Name())
case mode.IsRegular():
fmt.Printf("%#s is a file
", f.Name())
}
}
}
I'm not really sure why it is behaving like this, I'm new to Go. My guess is because it's being imported through main.go. How can I make it only search for folders and files in ./myfolder
?