Add file util for later
This commit is contained in:
24
utils/file.go
Normal file
24
utils/file.go
Normal file
@@ -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))
|
||||||
|
}
|
Reference in New Issue
Block a user