package main import ( "fmt" "os" ) func main() { fileInfo, err := os.Stat("example.txt") if err != nil { fmt.Println(err) return } fmt.Println(fileInfo.Name()) // Output: example.txt fmt.Println(fileInfo.Mode()) // Output: -rw-r--r-- fmt.Println(fileInfo.Size()) // Output: 1024 fmt.Println(fileInfo.ModTime()) // Output: 2021-07-27 10:12:34.567890123 +0000 UTC fmt.Println(fileInfo.IsDir()) // Output: false fmt.Println(fileInfo.Sys()) // Output: &{0 23456789} }
package main import ( "fmt" "os" ) func main() { fileInfo, err := os.Stat(".") if err != nil { fmt.Println(err) return } fmt.Println(fileInfo.Name()) // Output: . fmt.Println(fileInfo.Mode()) // Output: drwxr-xr-x fmt.Println(fileInfo.Size()) // Output: 4096 fmt.Println(fileInfo.ModTime()) // Output: 2021-07-27 10:12:34.567890123 +0000 UTC fmt.Println(fileInfo.IsDir()) // Output: true fmt.Println(fileInfo.Sys()) // Output: &{0 23456789} }This example demonstrates how to use the os.Stat method to get file information for the current directory. The output shows the name, mode, size, modification time, and whether the file is a directory. The Sys field returns system-specific information about the file. Package library: os