Standard library / os

os.Lstat()

Returns metadata about a named entry itself, including a symlink rather than following its target. Example uses a disposable temporary workspace. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func Lstat(name string) (FileInfo, error)

Parameters & Attributes

NameTypeDescription
namestringName or pathname of the target.

Return Value

(FileInfo, error)

Returns metadata about a named entry itself, including a symlink rather than following its target.

Working Example

Example Snippetgo
package main
import (  "fmt"  "os")
func check(e error) {  if e != nil {    panic(e)  }}func seed() { check(os.WriteFile("a.txt", []byte("abc"), 0600)) }func workspace() func() {  root, e := os.MkdirTemp("", "bytemind-go-")  check(e)  old, e := os.Getwd()  check(e)  check(os.Chdir(root))  return func() { check(os.Chdir(old)); check(os.RemoveAll(root)) }}func main() {  defer workspace()()  seed()  check(os.Symlink("a.txt", "alias"))  i, e := os.Lstat("alias")  check(e)  fmt.Println(i.Mode()&os.ModeSymlink != 0)}
Go Reference