GO语言"path/filepath"包中"Dir"函数的用法及代码示例。
用法:
func Dir(path string) string
Dir 返回除了路径的最后一个元素之外的所有元素,通常是路径的目录。删除最后一个元素后,Dir 在路径上调用 Clean 并删除尾部斜杠。如果路径为空,Dir 返回"."。如果路径完全由分隔符组成,则 Dir 返回单个分隔符。返回的路径不以分隔符结尾,除非它是根目录。
例子:
package main
import (
"fmt"
"path/filepath"
)
func main() {
fmt.Println("On Unix:")
fmt.Println(filepath.Dir("/foo/bar/baz.js"))
fmt.Println(filepath.Dir("/foo/bar/baz"))
fmt.Println(filepath.Dir("/foo/bar/baz/"))
fmt.Println(filepath.Dir("/dirty//path///"))
fmt.Println(filepath.Dir("dev.txt"))
fmt.Println(filepath.Dir("../todo.txt"))
fmt.Println(filepath.Dir(".."))
fmt.Println(filepath.Dir("."))
fmt.Println(filepath.Dir("/"))
fmt.Println(filepath.Dir(""))
}
输出:
On Unix: /foo/bar /foo/bar /foo/bar/baz /dirty/path . .. . . / .
相关用法
- GO Dir用法及代码示例
- GO Dial用法及代码示例
- GO Div64用法及代码示例
- GO Dialer用法及代码示例
- GO Div32用法及代码示例
- GO Dim用法及代码示例
- GO DecodeLastRuneInString用法及代码示例
- GO DumpResponse用法及代码示例
- GO DB.QueryRowContext用法及代码示例
- GO Date用法及代码示例
- GO DB.ExecContext用法及代码示例
- GO DB.BeginTx用法及代码示例
- GO Decoder.Token用法及代码示例
- GO Decoder.Decode用法及代码示例
- GO DumpRequest用法及代码示例
- GO Drawer用法及代码示例
- GO Duration.Hours用法及代码示例
- GO Duration.Round用法及代码示例
- GO DecodeRuneInString用法及代码示例
- GO DumpRequestOut用法及代码示例
注:本文由纯净天空筛选整理自golang.google.cn大神的英文原创作品 Dir。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。