package main import ( "fmt" "os" ) func main() { fileInfo, err := os.Stat("file.txt") if err != nil { fmt.Println(err) } fmt.Println("Size of file:", fileInfo.Size()) }
package main import ( "fmt" "os" ) func main() { fileInfo, err := os.Stat("folder") if err != nil { fmt.Println(err) } fmt.Println("Size of folder:", fileInfo.Size()) }This example retrieves information about a folder named "folder" and prints its size in bytes. However, since a folder is not a regular file, it will return a size of 0.