文件操作
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
951 B

package file
import (
"log"
"os"
"strings"
)
func Substr(s string, pos, length int) string {
runes := []rune(s)
l := pos + length
if l > len(runes) {
l = len(runes)
}
return string(runes[pos:l])
}
func GetParentDirectory(dirctory, SEPARATOR string) string {
currentDir := strings.TrimRight(dirctory, SEPARATOR)
return Substr(currentDir, 0, strings.LastIndex(currentDir, SEPARATOR))
}
/**
* 创建目录
*/
func CreatePath(path string) error {
DirStat, err := os.Stat(path)
if err != nil || !DirStat.IsDir() {
err := os.MkdirAll(path, 0755)
if err != nil {
log.Println("ERROR|", path, "目录创建失败", err)
}
}
// _, err := os.Stat(path) //检查目录是否存在
// if err != nil {
// cmd := exec.Command("/bin/sh", "-c", "mkdir -p "+path)
// if runtime.GOOS == "windows" {
// cmd = exec.Command("cmd", "/C", "md "+path)
// } else {
// }
// err := cmd.Run()
// return err
// }
return err
}