增加删除目录方法

This commit is contained in:
白茶清欢 2022-06-14 20:16:28 +08:00
parent 6af88e80af
commit d0ba29d5bc

22
dir.go
View File

@ -8,6 +8,8 @@
package command
import (
"errors"
"path/filepath"
"strings"
"git.zhangdeman.cn/zhangdeman/command/define"
@ -55,3 +57,23 @@ func (d *dir) Create(dirPath string) *define.Result {
paramList = append(paramList, dirPath)
return Execute(d.workDir, "mkdir", paramList)
}
// Delete 删除目录
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 20:12 2022/6/14
func (d *dir) Delete(dirPath string) *define.Result {
if strings.HasPrefix(dirPath, string(filepath.Separator)) && !strings.HasPrefix(dirPath, d.workDir) {
return &define.Result{
WorkDir: d.workDir,
CmdPath: "",
Param: nil,
Error: errors.New("仅允许删除工作目录下的子目录"),
Output: nil,
StartTime: 0,
FinishTime: 0,
}
}
return Execute(d.workDir, "rm", []string{"-rf", dirPath})
}