filepath Dir()

DIr函数: golang

1,返回除去最后一个元素和/以后的路径 函数

2,若是参数为空,返回. spa

3,若是路径内有隔断 返回一个/ test

一下是例子 file

func OsArgesText() { path

    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")) } //返回值: /
相关文章
相关标签/搜索