Documentation
¶
Index ¶
- Constants
- Variables
- func Base(path string) string
- func Clean(path string) string
- func Dir(path string) string
- func EvalSymlinks(path string) (string, error)
- func Glob(pattern string) (matches []string, err error)
- func Join(elem ...string) string
- func Match(pattern, name string) (matched bool, err error)
- func Split(path string) (dir, file string)
- func Walk(root string, walkFn WalkFunc) error
- type WalkFunc
Constants ¶
View Source
const ( Separator = os.PathSeparator ListSeparator = os.PathListSeparator )
只考虑linux
Variables ¶
View Source
var ErrBadPattern = errors.New("syntax error in pattern")
View Source
var (
ErrTooManyLinks = errors.New("EvalSymlinks: too many links")
)
View Source
var SkipDir = errors.New("skip this directory")
标识是否跳过本文件所在的目录,不继续扫描本文件所在的目录
Functions ¶
func Clean ¶
Clean清理path中多余的字符, 且如果不是根目录最后一个字符不会是分隔符
清理规则: 1. 去除path中多余分隔符Separator 2. 忽略path中的'./'目录。 因为'./'代表当前目录 3. 去除'../'及其之前的目录,如果'../'之前存在目录的话。因为'../'代表父目录 4. 如果'../'之前是根目录的话,直接去除。因为根目录之前没有目录 如果path为空的话,返回当前目录'.'
func EvalSymlinks ¶
func Glob ¶
Glob 根据输入的pattern匹配所有的文件。如果没有匹配到,返回nil
Glob 递归match 1. 假定第n级dirs已经匹配,那么就需要遍历dirs调用glob匹配file,得到第n+1 dirs 2. 递归终止条件,dir已经匹配展开
func Match ¶
Match 匹配
'/'分割符需要特殊处理,不能用'*'匹配 '*' 匹配任意非分隔符的字符 '?' 匹配任意一个非分割符的字符 [] 范围匹配,内不支持'*', '?'的上述作用 \\ 转义字符
Types ¶
Click to show internal directories.
Click to hide internal directories.