48 lines
926 B
Go
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
|
|
}
|