diff --git a/directories_test.go b/directories_test.go new file mode 100644 index 0000000000..b48074a2bd --- /dev/null +++ b/directories_test.go @@ -0,0 +1,10 @@ + package koii + +import ( + "fmt" + "os" + "path/filepath" +) + +// CreateDirectory creates a new directory at the specified path +// \ No newline at end of file diff --git a/utilities.go b/utilities.go new file mode 100644 index 0000000000..454ab285ba --- /dev/null +++ b/utilities.go @@ -0,0 +1,29 @@ + ```go +package utilities + +import ( + "fmt" + "path/filepath" + "strings" + + "github.com/go-kit/kit/log" + "github.com/go-kit/kit/log/level" + "github.com/gocarina/gocsv" +) + +// CreateDirectory creates a new directory with the given path +func CreateDirectory(path string, perm uint32) error { + path, err := filepath.Abs(path) + if err != nil { + return fmt.Errorf("failed to normalize path: %w", err) + } + + if _, err := os.Stat(path); err == nil { + return fmt.Errorf("directory already exists") + } else if !os.IsNotExist(err) { + return fmt.Errorf("failed to check if directory exists: %w", err) + } + + err = os.MkdirAll(path, perm) + if err != nil { + \ No newline at end of file