math-optim/util/util.go
surtur be55fc7d99
All checks were successful
continuous-integration/drone/push Build is passing
go: mv util{_test}.go to a separate util pkg
2022-07-10 20:54:48 +02:00

48 lines
926 B
Go

// Copyright 2022 wanderer <a_mirre at utb dot cz>
// SPDX-License-Identifier: GPL-3.0-or-later
package util
import (
"errors"
"log"
"os"
"strings"
)
// SanitiseFName clears spaces from the string that is supposed to be a file
// name.
func SanitiseFName(s string) string {
return strings.ReplaceAll(s, " ", "_")
}
// CreateFolder creates a folder at the specified path, if it doesn't already
// exist.
func CreateFolder(path string) error {
var err error
if _, err = os.Stat(path); errors.Is(err, os.ErrNotExist) {
err = os.Mkdir(path, os.ModePerm)
if err != nil {
log.Println(err)
}
}
return err
}
// CreatePath creates all folders in the provided path, if they don't already
// exist.
func CreatePath(path string) error {
var err error
if _, err = os.Stat(path); errors.Is(err, os.ErrNotExist) {
err = os.MkdirAll(path, os.ModePerm)
if err != nil {
log.Println(err)
}
}
return err
}