math-optim/algo/util.go
surtur b9a4ff3192
All checks were successful
continuous-integration/drone/push Build is passing
go(algo/util): add createPath func
2022-06-29 16:54:55 +02:00

46 lines
840 B
Go

// Copyright 2022 wanderer <a_mirre at utb dot cz>
// SPDX-License-Identifier: GPL-3.0-or-later
package algo
import (
"errors"
"log"
"os"
"strings"
)
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
}