package main import ( "fmt" "os" "path/filepath" "strings" ) func destorytemp(path string) { filepath.Walk(path, func(path string, fi os.FileInfo, err error) error { if nil == fi { return err } if !fi.IsDir() { return nil } name := fi.Name() if strings.Contains(name, "temp") { fmt.Println("temp file name:", path) err := os.RemoveAll(path) if err != nil { fmt.Println("delet dir error:", err) } } return nil }) } func createtmpdir() { f, e := ioutil.TempDir("C:/Documents and Settings/xxxx/Desktop/Copy of change-sub", "temp") if e != nil { fmt.Println("create tempDir error") return } fmt.Println(f) } func main() { createtmpdir() destorytemp("C:/Documents and Settings/xxxx/Desktop/Copy of change-sub") }