package main import ( "fmt" "os" ) func main() { fileInfo, err := os.Stat("/home/user/Documents") if err != nil { fmt.Println(err) } else { if fileInfo.IsDir() { fmt.Println("Directory") } else { fmt.Println("Not a directory") } } }
package main import ( "fmt" "os" ) func main() { fileInfo, err := os.Stat("/home/user/test.txt") if err != nil { fmt.Println(err) } else { if fileInfo.IsDir() { fmt.Println("Directory") } else { fmt.Println("Not a directory") } } }This code example checks if the "/home/user/test.txt" file is a directory or not. Since it is a file and not a directory, the output will be "Not a directory". In both examples, the os package library is used to access the file system and determine whether a path refers to a directory or not.