package main import ( "fmt" "os" ) func main() { file, err := os.Open("example.txt") if err != nil { fmt.Println("Error opening file:", err) return } defer file.Close() fileInfo, err := file.Stat() if err != nil { fmt.Println("Error getting file info:", err) return } fmt.Println("File name:", fileInfo.Name()) fmt.Println("File size:", fileInfo.Size()) fmt.Println("File mode:", fileInfo.Mode()) fmt.Println("Last modified:", fileInfo.ModTime()) }
package main import ( "fmt" "os" ) func main() { dirPath := "." dir, err := os.Open(dirPath) if err != nil { fmt.Println("Error opening directory:", err) return } defer dir.Close() fileInfoList, err := dir.Readdir(0) if err != nil { fmt.Println("Error reading directory:", err) return } for _, fileInfo := range fileInfoList { fmt.Println("File name:", fileInfo.Name()) fmt.Println("File size:", fileInfo.Size()) fmt.Println("File mode:", fileInfo.Mode()) fmt.Println("Last modified:", fileInfo.ModTime()) } }The package for these examples is os.