1
0
mirror of https://github.com/MADTeacher/go_basics.git synced 2025-11-23 21:34:47 +02:00
Files
go_basics/part_5/5.2/6.go
2025-06-14 12:40:10 +03:00

27 lines
545 B
Go

package main
import (
"fmt"
"log"
"os"
"path/filepath"
)
func main() {
path := "C:\\Go" // целевая директория
files, err := os.ReadDir(path) // тип возвращаемого значения - []fs.FileInfo
if err != nil {
log.Fatal(err)
}
for _, file := range files {
if file.IsDir() {
fmt.Printf("%s is directory. Path: %v\n",
file.Name(), filepath.Join(path, file.Name()))
} else {
fmt.Printf("%s is file. Path: %v\n",
file.Name(), filepath.Join(path, file.Name()))
}
}
}