Find files in directory

please, help,
task to find all the files of a certain extension in one directory, how I can do this?

For example so:

package main

import (

func main() {

	files, err := ioutil.ReadDir("./")
	if err != nil {

	target := []os.FileInfo{}

	for _, f := range files {
		if !f.IsDir() && strings.HasSuffix(f.Name(), ".go") {
			target = append(target, f)


But it would be better if you provided your code first.


thanks man , it work for me

You can also use filepath.Walk, especially for very large directories.


The linked documentation says it were inefficient for large directories…

1 Like

I used for large directories (on Linux) and I didn’t feel a lack of performance. Perhaps could be ineficient for realy very large directories…

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.