<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # package path `import "path"` path實現了對斜杠分隔的路徑的實用操作函數。 ## Index * [Variables](#pkg-variables) * [func IsAbs(path string) bool](#IsAbs) * [func Split(path string) (dir, file string)](#Split) * [func Join(elem ...string) string](#Join) * [func Dir(path string) string](#Dir) * [func Base(path string) string](#Base) * [func Ext(path string) string](#Ext) * [func Clean(path string) string](#Clean) * [func Match(pattern, name string) (matched bool, err error)](#Match) ### Examples * [Base](#example-Base) * [Clean](#example-Clean) * [Dir](#example-Dir) * [Ext](#example-Ext) * [IsAbs](#example-IsAbs) * [Join](#example-Join) * [Split](#example-Split) ## Variables ``` var ErrBadPattern = errors.New("syntax error in pattern") ``` ErrBadPattern表示一個glob模式匹配字符串的格式錯誤。 ## func [IsAbs](https://github.com/golang/go/blob/master/src/path/path.go#L196 "View Source") ``` func IsAbs(path string) bool ``` IsAbs返回路徑是否是一個絕對路徑。 Example ``` fmt.Println(path.IsAbs("/dev/null")) ``` Output: ``` true ``` ## func [Split](https://github.com/golang/go/blob/master/src/path/path.go#L142 "View Source") ``` func Split(path string) (dir, file string) ``` Split函數將路徑從最后一個斜杠后面位置分隔為兩個部分(dir和file)并返回。如果路徑中沒有斜杠,函數返回值dir會設為空字符串,file會設為path。兩個返回值滿足path == dir+file。 Example ``` fmt.Println(path.Split("static/myfile.css")) ``` Output: ``` static/ myfile.css ``` ## func [Join](https://github.com/golang/go/blob/master/src/path/path.go#L150 "View Source") ``` func Join(elem ...string) string ``` Join函數可以將任意數量的路徑元素放入一個單一路徑里,會根據需要添加斜杠。結果是經過簡化的,所有的空字符串元素會被忽略。 Example ``` fmt.Println(path.Join("a", "b", "c")) ``` Output: ``` a/b/c ``` ## func [Dir](https://github.com/golang/go/blob/master/src/path/path.go#L207 "View Source") ``` func Dir(path string) string ``` Dir返回路徑除去最后一個路徑元素的部分,即該路徑最后一個元素所在的目錄。在使用Split去掉最后一個元素后,會簡化路徑并去掉末尾的斜杠。如果路徑是空字符串,會返回".";如果路徑由1到多個斜杠后跟0到多個非斜杠字符組成,會返回"/";其他任何情況下都不會返回以斜杠結尾的路徑。 Example ``` fmt.Println(path.Dir("/a/b/c")) ``` Output: ``` /a/b ``` ## func [Base](https://github.com/golang/go/blob/master/src/path/path.go#L176 "View Source") ``` func Base(path string) string ``` Base函數返回路徑的最后一個元素。在提取元素前會求掉末尾的斜杠。如果路徑是"",會返回".";如果路徑是只有一個斜桿構成,會返回"/"。 Example ``` fmt.Println(path.Base("/a/b")) ``` Output: ``` b ``` ## func [Ext](https://github.com/golang/go/blob/master/src/path/path.go#L163 "View Source") ``` func Ext(path string) string ``` Ext函數返回path文件擴展名。返回值是路徑最后一個斜杠分隔出的路徑元素的最后一個'.'起始的后綴(包括'.')。如果該元素沒有'.'會返回空字符串。 Example ``` fmt.Println(path.Ext("/a/b/c/bar.css")) ``` Output: ``` .css ``` ## func [Clean](https://github.com/golang/go/blob/master/src/path/path.go#L69 "View Source") ``` func Clean(path string) string ``` Clean函數通過單純的詞法操作返回和path代表同一地址的最短路徑。 它會不斷的依次應用如下的規則,直到不能再進行任何處理: ``` 1\. 將連續的多個斜杠替換為單個斜杠 2\. 剔除每一個.路徑名元素(代表當前目錄) 3\. 剔除每一個路徑內的..路徑名元素(代表父目錄)和它前面的非..路徑名元素 4\. 剔除開始一個根路徑的..路徑名元素,即將路徑開始處的"/.."替換為"/" ``` 只有路徑代表根地址"/"時才會以斜杠結尾。如果處理的結果是空字符串,Clean會返回"."。 參見[http://plan9.bell-labs.com/sys/doc/lexnames.html](http://plan9.bell-labs.com/sys/doc/lexnames.html) Example ``` paths := []string{ "a/c", "a//c", "a/c/.", "a/c/b/..", "/../a/c", "/../a/b/../././/c", } for _, p := range paths { fmt.Printf("Clean(%q) = %q\n", p, path.Clean(p)) } ``` Output: ``` Clean("a/c") = "a/c" Clean("a//c") = "a/c" Clean("a/c/.") = "a/c" Clean("a/c/b/..") = "a/c" Clean("/../a/c") = "/a/c" Clean("/../a/b/../././/c") = "/a/c" ``` ## func [Match](https://github.com/golang/go/blob/master/src/path/match.go#L38 "View Source") ``` func Match(pattern, name string) (matched bool, err error) ``` 如果name匹配shell文件名模式匹配字符串,Match函數返回真。該模式匹配字符串語法為: ``` pattern: { term } term: '*' 匹配0或多個非/的字符 '?' 匹配1個非/的字符 '[' [ '^' ] { character-range } ']' 字符組(必須非空) c 匹配字符c(c != '*', '?', '\\', '[') '\\' c 匹配字符c character-range: c 匹配字符c(c != '\\',?'-', ']') '\\' c 匹配字符c lo '-' hi 匹配區間[lo, hi]內的字符 ``` Match要求匹配整個name字符串,而不是它的一部分。只有pattern語法錯誤時,會返回ErrBadPattern。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看