package main import ( "flag" "fmt" "os" "os/exec" "runtime" "strings" ) var target = "../www/" func main() { fmt.Println("=============start==============") dir := flag.String("dir", "yyq_admin", "dir") flag.Parse() target += *dir + "/" fmt.Println("target_dir", target) os.RemoveAll(target + "static") os.RemoveAll(target + "manage") os.Remove(target + "index.html") os.Remove(target + "favicon.ico") os.Remove(target + "favicon.jpg") copyDir("./dist", target) } func FormatPath(s string) string { switch runtime.GOOS { case "windows": return strings.Replace(s, "/", "\\", -1) case "darwin", "linux": return strings.Replace(s, "\\", "/", -1) default: return s } } func copyDir(src string, dest string) { src = FormatPath(src) dest = FormatPath(dest) var cmd *exec.Cmd switch runtime.GOOS { case "windows": cmd = exec.Command("xcopy", src, dest, "/I", "/E") case "darwin", "linux": cmd = exec.Command("cp", "-R", src, dest) } outPut, e := cmd.Output() if e != nil { fmt.Println("copy error", e.Error()) return } fmt.Println(string(outPut)) }