删除目录和所有子目录

This is what I tried:

package main

import (
    "fmt"
    "os/exec"
)

func main() {
    fmt.Println("Removing build directory")
    if err := exec.Command("cmd", "/S /Q", "RD", "c:\\build").Run(); err != nil {
        fmt.Printf("Error removing build directory: %s
", err)
    }

    if err := exec.Command("cmd", "/C", "mkdir", "c:\\build").Run(); err != nil {
        fmt.Printf("Error making new build directory: %s
", err)
    }
}

And my output is:

Removing build directory
Error making new build directory: exit status 1

So I don't get any error when removing, but it doesn't delete anything.

Why is that ?

Try this..

func main() {
    fmt.Println("Removing build directory")

   c := exec.Command("cmd", "/C", "rd /S /Q", "C:\\build")

    if err := c.Run(); err != nil { 
        fmt.Println("Error: ", err)
    }  


    if err := exec.Command("cmd", "/C", "mkdir", "c:\\build").Run(); err != nil {
        fmt.Printf("Error making new build directory: %s
", err)
    }

}