Logo

Programming-Idioms

History of Idiom 212 > diff from v3 to v4

Edit summary for version 4 by programming-idioms.org:
[Go] Fix demo

Version 3

2019-10-21, 20:31:00

Version 4

2019-10-21, 20:32:36

Idiom #212 Check if folder exists

Set boolean b to true if path exists on the filesystem and is a directory; false otherwise.

Idiom #212 Check if folder exists

Set boolean b to true if path exists on the filesystem and is a directory; false otherwise.

Extra Keywords
test whether existence
Extra Keywords
test whether existence
Imports
import "os"
Imports
import "os"
Code
info, err := os.Stat(path)
b := !os.IsNotExist(err) && info.IsDir()
Code
info, err := os.Stat(path)
b := !os.IsNotExist(err) && info.IsDir()
Doc URL
https://golang.org/pkg/os/#Stat
Doc URL
https://golang.org/pkg/os/#Stat
Demo URL
https://play.golang.org/p/eX3zrCCX3t2
Demo URL
https://play.golang.org/p/jYkbld5ACiy