Golang io/ioutil.TempDir() function example

package io/ioutil

Golang io/ioutil.TempDir() function usage example

 package main

 import (
 "fmt"
 "io/ioutil"
 )

 func main() {

 dir := "./"
 prefix := "new"

 name, err := ioutil.TempDir(dir, prefix)

 if err != nil {
 fmt.Println(err)
 }

 // TempDir will create "new" directory
 // and you need to capture the name of the temp directory
 // to remove it later
 fmt.Printf("%s \n", name)

 }

Reference :

http://golang.org/pkg/io/ioutil/#TempDir

Advertisement