33 lines
644 B
Go
33 lines
644 B
Go
package file
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
// PathInfo 路径信息
|
|
type PathInfo struct {
|
|
Dir string // 目录
|
|
Ext string // 扩展名
|
|
FileName string // 没有扩展名的文件名名称
|
|
FullFileName string // 文件全名
|
|
}
|
|
|
|
// GetPathInfo 解析路径
|
|
// 返回文件,路径,文件名等信息
|
|
func GetPathInfo(path string) (pi PathInfo) {
|
|
if path == "" {
|
|
return
|
|
}
|
|
if !filepath.IsAbs(path) {
|
|
path, _ = filepath.Abs(path)
|
|
}
|
|
ext := filepath.Ext(path)
|
|
dir, name := filepath.Split(path)
|
|
pi.Dir = dir
|
|
pi.Ext = ext
|
|
pi.FileName = strings.TrimRight(name, ext)
|
|
pi.FullFileName = name
|
|
return
|
|
}
|