How can I add to list only files?

I have a list. I would like to add to my list only files. I’ trying to add to it so. But I’m getting an error.

first argument to append must be slice; have interface { IsDir() bool; ModTime() time.Time; Mode() _
os.FileMode; Name() string; Size() int64; Sys() interface {} }
package main

import (

func main() {
    filepath := "target"
    files_dirs, err := ioutil.ReadDir(filepath)
    if err != nil {

    list := []string{} // I need to add here
    for _, x := range files_dirs {
	    if x.IsDir() == false {
		    list = append(x)

Append can’t guess what to append to.

list = append(list, x.Name())

1 Like

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