Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Created June 30, 2018 10:38
Show Gist options
  • Save miguelmota/d065806656c81021527069f3877fa762 to your computer and use it in GitHub Desktop.
Save miguelmota/d065806656c81021527069f3877fa762 to your computer and use it in GitHub Desktop.
Golang create temporary directory
package main
import (
"fmt"
"io/ioutil"
"log"
)
func main() {
tmp, err := ioutil.TempDir("", "")
if err != nil {
log.Fatal(err)
}
fmt.Println(tmp) // /var/folders/k1/m2rmftgd48q97pj0xf9csdb00000gn/T/254614131
}
@EricMountain
Copy link

In case someone else lands here searching for this: as of Go 1.17 ioutil.TempDir() is deprecated in favour of os.MkdirTemp() (same arguments, same behaviour, drop-in replacement).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment