Answer the question
In order to leave comments, you need to log in
How to cast os.FileInfo type to string type?
How to cast os.FileInfo type to string type? What is there in os.FileInfo, besides the elements in the slice ?
In particular, I want to leave only files of a certain type in the slice of elements in the folder :
filesDir, err := ioutil.ReadDir(".")
for _, fileDir := range filesDir {
if filepath.Ext(string(fileDir)) == ".txt" && !fileDir.IsDir() {
fmt.Println("Файл(ы) .txt в текущей папке:", fileDir.Name())
}
}
Answer the question
In order to leave comments, you need to log in
ioutil.ReadDir returns [] fs.FileInfo
This is an interface, looks like this
type FileInfo interface {
Name() string // base name of the file
Size() int64 // length in bytes for regular files; system-dependent for others
Mode() FileMode // file mode bits
ModTime() time.Time // modification time
IsDir() bool // abbreviation for Mode().IsDir()
Sys() interface{} // underlying data source (can return nil)
}
type FileInfo = fs.FileInfo
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question