DIr函数:
1,返回除去最后一个元素和/之后的路径
2,如果参数为空,返回.
3,如果路径内有隔断 返回一个/
一下是例子
func OsArgesText() {
pth := os.Args[0]fmt.Println("pth="+pth)
fmt.Println(filepath.Dir(pth))
testDir1()
testDir2()
}
//返回值:pth=/home/zongjh/workspace/gotestworkspace/golangtest/bin/start
//返回值:/home/zongjh/workspace/gotestworkspace/golangtest/bin
func testDir1() {
fmt.Println(filepath.Dir(""))
}
//返回值: .
func testDir2() {
fmt.Println(filepath.Dir("/home hello"))
}
//返回值: /