方法
go
package zdpgo_file
import (
"os"
)
// AddDir 创建文件夹
func AddDir(dir string) error {
if !IsExist(dir) {
return os.MkdirAll(dir, os.ModePerm)
}
return nil
}
测试
go
package zdpgo_file
import "testing"
func TestAddDir(t *testing.T) {
data := []string{
"test",
"test/a1",
"test/a2/a3",
}
for _, tt := range data {
v := AddDir(tt)
if v != nil {
t.Error(v)
}
}
}
测试结果

