Files
QSfera/vendor/github.com/gookit/goutil/fsutil/info.go
T
dependabot[bot]andRalf Haferkamp 0df009eae0 Bump github.com/gookit/config/v2 from 2.2.3 to 2.2.4
Bumps [github.com/gookit/config/v2](https://github.com/gookit/config) from 2.2.3 to 2.2.4.
- [Release notes](https://github.com/gookit/config/releases)
- [Commits](https://github.com/gookit/config/compare/v2.2.3...v2.2.4)

---
updated-dependencies:
- dependency-name: github.com/gookit/config/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-03 10:26:28 +01:00

71 lines
1.7 KiB
Go

package fsutil
import (
"os"
"path"
"path/filepath"
"github.com/gookit/goutil/internal/comfunc"
)
// DirPath get dir path from filepath, without last name.
func DirPath(fpath string) string { return filepath.Dir(fpath) }
// Dir get dir path from filepath, without last name.
func Dir(fpath string) string { return filepath.Dir(fpath) }
// PathName get file/dir name from full path
func PathName(fpath string) string { return path.Base(fpath) }
// Name get file/dir name from full path.
//
// eg: path/to/main.go => main.go
func Name(fpath string) string {
if fpath == "" {
return ""
}
return filepath.Base(fpath)
}
// FileExt get filename ext. alias of path.Ext()
//
// eg: path/to/main.go => ".go"
func FileExt(fpath string) string { return path.Ext(fpath) }
// Extname get filename ext. alias of path.Ext()
//
// eg: path/to/main.go => "go"
func Extname(fpath string) string {
if ext := path.Ext(fpath); len(ext) > 0 {
return ext[1:]
}
return ""
}
// Suffix get filename ext. alias of path.Ext()
//
// eg: path/to/main.go => ".go"
func Suffix(fpath string) string { return path.Ext(fpath) }
// Expand will parse first `~` as user home dir path.
func Expand(pathStr string) string {
return comfunc.ExpandHome(pathStr)
}
// ExpandPath will parse `~` as user home dir path.
func ExpandPath(pathStr string) string {
return comfunc.ExpandHome(pathStr)
}
// ResolvePath will parse `~` and env var in path
func ResolvePath(pathStr string) string {
pathStr = comfunc.ExpandHome(pathStr)
// return comfunc.ParseEnvVar()
return os.ExpandEnv(pathStr)
}
// SplitPath splits path immediately following the final Separator, separating it into a directory and file name component
func SplitPath(pathStr string) (dir, name string) {
return filepath.Split(pathStr)
}