improved file read/copy logic
This commit is contained in:
29
util.go
Normal file
29
util.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Exists(p ...string) (bool, error) {
|
||||
_, err := os.Stat(path.Join(p...))
|
||||
if err == nil {
|
||||
return true, nil
|
||||
}
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
|
||||
func SplitExt(filename string) (string, string) {
|
||||
ext := strings.ToUpper(path.Ext(filename))
|
||||
name := strings.ToUpper(filename[:len(filename)-len(ext)])
|
||||
if len(ext) > 0 {
|
||||
ext = ext[1:]
|
||||
}
|
||||
return name, ext
|
||||
}
|
||||
Reference in New Issue
Block a user