feat: allow to specify output dir; process dir recursively

This commit is contained in:
2024-09-27 22:22:56 +08:00
parent 30a50c1eae
commit b104e1352f
2 changed files with 112 additions and 35 deletions

View File

@@ -1,6 +1,7 @@
package utils
import (
"os"
"path/filepath"
"strings"
)
@@ -9,3 +10,39 @@ func ReplaceExtension(filepathStr, newExt string) string {
ext := filepath.Ext(filepathStr)
return strings.TrimSuffix(filepathStr, ext) + newExt
}
func PathExists(path string) bool {
_, err := os.Stat(path)
if err == nil {
return true
}
if os.IsNotExist(err) {
return false
}
return false
}
func IsDir(path string) bool {
s, err := os.Stat(path)
if err != nil {
return false
}
return s.IsDir()
}
func GetRelativePath(from, to string) string {
rel, err := filepath.Rel(from, to)
if err != nil {
return ""
}
return rel
}
func IsRegularFile(path string) bool {
s, err := os.Stat(path)
if err != nil {
return false
}
return s.Mode().IsRegular()
}