增加创建目录方法
This commit is contained in:
parent
6e8f81cee0
commit
666a0dbab6
57
dir.go
Normal file
57
dir.go
Normal file
@ -0,0 +1,57 @@
|
||||
// Package command ...
|
||||
//
|
||||
// Description : command ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2022-05-21 17:31
|
||||
package command
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/command/define"
|
||||
)
|
||||
|
||||
// Dir 目录操作实例
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:33 2022/5/21
|
||||
func Dir(workDir string) *dir {
|
||||
return &dir{
|
||||
workDir: workDir,
|
||||
}
|
||||
}
|
||||
|
||||
type dir struct {
|
||||
workDir string // 工作目录
|
||||
recursiveCreate bool // 创建目录时,是否递归创建
|
||||
}
|
||||
|
||||
// RecursiveCreate 递归创建目录
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:37 2022/5/21
|
||||
func (d *dir) RecursiveCreate() *dir {
|
||||
d.recursiveCreate = true
|
||||
return d
|
||||
}
|
||||
|
||||
// Create 创建目录, 若 dirPath 以 / 开头, 则为据对路径, 否则是相对 workDir 的相对路径
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:42 2022/5/21
|
||||
func (d *dir) Create(dirPath string) define.Result {
|
||||
if !strings.HasPrefix(dirPath, "/") {
|
||||
dirPath = strings.ReplaceAll(d.workDir, "//", "/")
|
||||
}
|
||||
paramList := make([]string, 0)
|
||||
if d.recursiveCreate {
|
||||
paramList = append(paramList, "-p")
|
||||
}
|
||||
paramList = append(paramList, dirPath)
|
||||
return Execute(d.workDir, "mkdir", paramList)
|
||||
}
|
Loading…
Reference in New Issue
Block a user