pikapika/go/main/utils/file.go

31 lines
630 B
Go
Raw Normal View History

2021-09-29 23:57:09 +00:00
package utils
import (
"os"
2021-10-25 11:27:38 +00:00
"strings"
2021-09-29 23:57:09 +00:00
)
func Mkdir(dir string) {
if _, err := os.Stat(dir); err != nil {
if os.IsNotExist(err) {
2021-10-22 02:24:39 +00:00
err = os.MkdirAll(dir, CreateDirMode)
2021-09-29 23:57:09 +00:00
if err != nil {
panic(err)
}
} else {
panic(err)
}
}
}
2021-10-25 11:27:38 +00:00
func ReasonableFileName(title string) string {
title = strings.ReplaceAll(title, "\\", "_")
title = strings.ReplaceAll(title, "/", "_")
title = strings.ReplaceAll(title, "*", "_")
title = strings.ReplaceAll(title, "?", "_")
title = strings.ReplaceAll(title, "<", "_")
title = strings.ReplaceAll(title, ">", "_")
title = strings.ReplaceAll(title, "|", "_")
return title
}