package models

import (
	"io/ioutil"
	"os"
	"runtime"
)

type DeleteAll struct {
}

// 递归循环删除目录及文件
func (this *DeleteAll) Dir(d string) bool {
	if d[len(d)-1:] == "/" {
		d = d[0 : len(d)-1]
	}
	files, err := ioutil.ReadDir(d)
	if err != nil {
		return false
	}
	fuhk := "/"
	if runtime.GOOS == "windows" {
		fuhk = "\\"
	}
	for _, v := range files {
		if v.IsDir() {
			path := d + fuhk + v.Name()
			this.Dir(path)
		} else {
			os.Remove(v.Name())
		}
	}
	return true
}
