From 58586395fb4327dc7c79566b51257c1653ec8c9c Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Sun, 13 Apr 2025 21:31:19 +0200 Subject: [PATCH] Add file util for later --- utils/file.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 utils/file.go diff --git a/utils/file.go b/utils/file.go new file mode 100644 index 0000000..d4f6e18 --- /dev/null +++ b/utils/file.go @@ -0,0 +1,24 @@ +package utils + +import ( + "os" + "path/filepath" + "strings" +) + +func CleanPath(path string) string { + path = filepath.Clean(path) + path = strings.ReplaceAll(path, "\\", "/") + return path +} + +func ToAbs(path string) string { + if filepath.IsAbs(path) { + return CleanPath(path) + } + cwd, err := os.Getwd() + if err != nil { + return CleanPath(path) + } + return CleanPath(filepath.Join(cwd, path)) +}