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 } modTime := fileInfo.ModTime() fmt.Println("Modification time:", modTime) }
package main import ( "fmt" "os" ) func main() { dir, err := os.Open(".") if err != nil { fmt.Println("Error opening directory:", err) return } defer dir.Close() dirInfo, err := dir.Stat() if err != nil { fmt.Println("Error getting directory info:", err) return } modTime := dirInfo.ModTime() fmt.Println("Modification time:", modTime) }In this example, we open the current directory instead of a file, and use `.ModTime()` to get the directory's modification time instead. The `os` package is used in both examples to interact with the file system and retrieve the necessary file or directory information.