Documentation ¶
Overview ¶
Package pathKit
@Author Richelieu @Description 主要是对"path"、"path/filepath"的封装.
PS: filepath标准库的使用可以参考: https://www.cnblogs.com/jkko123/p/6923962.html
Index ¶
- func CheckSkip(parent, path string) bool
- func Clean(path string) string
- func EvalSymlinks(path string) (string, error)
- func ExpandTilde(path string) (string, error)
- func FromSlash(path string) string
- func GetAbsolutePath(path string) (string, error)
- func GetHomeDir() string
- func GetOutputPath(timeStr string) (string, error)
- func GetParentDir(nameOrPath string) string
- func GetProjectDir() string
- func GetRelativePath(basePath, targetPath string) (string, error)
- func GetTempDir() string
- func GetUniqueTempDir() (string, error)
- func GetUserHomePath() string
- func Glob(pattern string) (matches []string, err error)
- func IsAbs(path string) bool
- func IsAbsolutePath(path string) bool
- func Join(eles ...string) string
- func Match(pattern, name string) (matched bool, err error)
- func SetProjectDir(dir string) error
- func Split(path string) (dir, file string)
- func SplitList(path string) []string
- func ToSlash(path string) string
- func VolumeName(path string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckSkip ¶
CheckSkip 检查是否发生"路径穿越"(路径穿透)
@param path 父路径 @param path1 子路径 @return true: 发生"路径穿越"
e.g. ("/a//b/", "/a//b//../c.docx") => true ("/a//b/", "//a//b///c.docx") => false
func Clean ¶
Clean 返回等价的最短路径(清理路径)
PS: 可用于去掉路径中的 "./" 、 "../" ...
e.g. ("./1.txt") => "1.txt" ("/root/.././c") => "/c"
func ExpandTilde ¶
ExpandTilde "~"(波浪号) => 当前用户主目录
e.g. ("") => "", nil ("~") => "/Users/richelieu", nil ("~/a/b/c") => "/Users/richelieu/a/b/c", nil
func GetAbsolutePath ¶
GetAbsolutePath 获取的绝对路径(传参path相对于当前路径(os.Getwd())).
func GetParentDir ¶
GetParentDir 返回文件(或目录)路径的父路径.
PS: 类似于Java中的 getParentFile().
@param nameOrPath 文件名或文件路径
e.g. ("") => "." (".") => "." ("yozo.eio") => "." ("/") => "/"
e.g.1 Mac ("./a/b/c") => "a/b" ("C:/a/b/c") => "C:/a/b"
func GetProjectDir ¶
func GetProjectDir() string
func GetRelativePath ¶
GetRelativePath 获取(targetPath 相对于 basePath 的)相对路径.
e.g. Windows ("C:/a/b", "C:/a/b/c/d/../e") => "c\e", <nil>
e.g.1 Mac ("/usr/local", "/usr/local/go/bin") => "go/bin", nil ("//usr////local", "/usr/local/go/bin") => "go/bin", nil ("//usr////local", "/usr/local/go/bin/../") => "go", nil
func GetTempDir ¶
func GetTempDir() string
GetTempDir 获取系统的临时目录.
e.g. Windows: "C:\Users\Lenovo\AppData\Local\Temp" Mac: "/var/folders/4_/33p_vn057msfh2nvgx6hwv_40000gn/T/"
func GetUniqueTempDir ¶
GetUniqueTempDir 获取 本依赖 的专属临时目录.
e.g. Mac () => "/var/folders/4_/33p_vn057msfh2nvgx6hwv_40000gn/T/$$chimera", nil
func GetUserHomePath ¶
func GetUserHomePath() string
func IsAbs ¶
IsAbs 判断路径是不是绝对路径
PS: 传参path 对应的文件(或目录)可以不存在.
e.g. ("./a/b/c") => false ("C:/a/b/c") => true ("/root") => true ("root") => false
func IsAbsolutePath ¶
IsAbsolutePath 是否绝对路径?
e.g. ("") => false ("./a/b/c") => false ("/a/b/c") => true
func Join ¶
Join 将多个字符串合并为一个路径(路径拼接).
PS: (1) 不建议用"path.Join",有问题,e.g. 传参:"d:\\nacos\\", "cyy" (2) 此方法也可用于优化路径(处理: 路径穿越、多个连续的路径分隔符...).
e.g. () => "" ("") => "" ("", "") => "" ("", "a") => "a"
(".", "yozo.eio") => "yozo.eio"
(" ") => " " (" ", "a") => " /a"
e.g.1 支持: 路径穿越(路径穿透) ("/a/b", "../c.docx") => "/a/c.docx"
func Match ¶
Match (正则相关)匹配文件名,完全匹配则返回true
e.g. ("*", "a") => (true, <nil>) ("*", "C:/a/b/c") => (true, <nil>) ("\\b", "b") => (false, <nil>)
func SetProjectDir ¶
func Split ¶
Split 分割路径中的目录与文件.
e.g. Mac ("/Users/richelieu/Downloads/") => "/Users/richelieu/Downloads/", "" ("/Users/richelieu/Downloads") => "/Users/richelieu/", "Downloads"
func SplitList ¶
SplitList 使用"路径列表分隔符"将路径分开.
os.PathListSeparator(linux下默认为':',windows下为';')
e.g. ("d:/a/b/c.docx") => [d:/a/b/c.docx] ("C:/windows;C:/windows/system") => [C:/windows C:/windows/system]
Types ¶
This section is empty.