Golang创建文件夹

方法

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)
		}
	}
}

测试结果

相关推荐
9***Y481 天前
Java开发工具IntelliJ IDEA技巧
java·开发语言·intellij-idea
码力码力我爱你1 天前
C++性能基准测试
开发语言·c++
张人玉1 天前
C#WPF——MVVM框架编写管理系统所遇到的问题
开发语言·c#·wpf·mvvm框架
q***96581 天前
深入解析Spring Boot中的@ConfigurationProperties注解
java·spring boot·后端
java1234_小锋1 天前
讲讲Mybatis的一级、二级缓存?
java·开发语言·mybatis
z***I3941 天前
JavaScript原型链
开发语言·前端·javascript
x***58701 天前
JavaScript语音识别开发
开发语言·javascript·语音识别
Jamesvalley1 天前
flask处理所有logging
后端·python·flask
小年糕是糕手1 天前
【C++】C++入门 -- 输入&输出、缺省参数
c语言·开发语言·数据结构·c++·算法·leetcode·排序算法
databook1 天前
别急着转投 Polars!Pandas 3.0 带着“黑科技”杀回来了
后端·python·数据分析