Home

Published

- 1 min read

golang create directory if not exists

img of golang create directory if not exists

The solution for this is noted below

golang create directory if not exists

Solution

   func createDirIfNotExists(path string) {
	exists, err := exists(path)
	if err != nil {
		panic(err)
	}
	if !exists {
		os.Mkdir(path, 0777)
	}
}

Try other methods by searching on the site. That is if this doesn’t work