Answer the question
In order to leave comments, you need to log in
How to search for files in only one folder; specify the current directory?
var files []string
var my_dir = "../testDir/"
var err = filepath.Walk(my_dir, func(path string, info os.FileInfo, err error) (error) {
if !info.IsDir() {
var ext = filepath.Ext(path)
if ext == ".tx" {
files = append(files, path)
}
}
return nil
})
Answer the question
In order to leave comments, you need to log in
To specify the current folder - you can specify "dot" as the folder name so that there is no recursion - use the ioutil.ReadDir function.
package main
import (
"fmt"
"io/ioutil"
"log"
)
func main() {
// текущая папка
files, err := ioutil.ReadDir(".")
if err != nil {
log.Fatal(err)
}
for _, file := range files {
fmt.Println(file.Name(), file.IsDir())
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question