<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # package filepath `import "path/filepath"` filepath包實現了兼容各操作系統的文件路徑的實用操作函數。 ## Index * [Constants](#pkg-constants) * [Variables](#pkg-variables) * [func IsAbs(path string) bool](#IsAbs) * [func Abs(path string) (string, error)](#Abs) * [func Rel(basepath, targpath string) (string, error)](#Rel) * [func SplitList(path string) []string](#SplitList) * [func Split(path string) (dir, file string)](#Split) * [func Join(elem ...string) string](#Join) * [func FromSlash(path string) string](#FromSlash) * [func ToSlash(path string) string](#ToSlash) * [func VolumeName(path string) (v string)](#VolumeName) * [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 EvalSymlinks(path string) (string, error)](#EvalSymlinks) * [func Match(pattern, name string) (matched bool, err error)](#Match) * [func Glob(pattern string) (matches []string, err error)](#Glob) * [type WalkFunc](#WalkFunc) * [func Walk(root string, walkFn WalkFunc) error](#Walk) * [func HasPrefix(p, prefix string) bool](#HasPrefix) ### Examples * [Rel](#example-Rel) * [SplitList](#example-SplitList) ## Constants ``` const ( Separator = os.PathSeparator ListSeparator = os.PathListSeparator ) ``` ## Variables ``` var ErrBadPattern = errors.New("syntax error in pattern") ``` ErrBadPattern表示一個glob模式匹配字符串的格式錯誤。 ``` var SkipDir = errors.New("skip this directory") ``` 用作WalkFunc類型的返回值,表示該次調用的path參數指定的目錄應被跳過。本錯誤不應被任何其他函數返回。 ## func [IsAbs](https://github.com/golang/go/blob/master/src/path/filepath/path_unix.go#L12 "View Source") ``` func IsAbs(path string) bool ``` IsAbs返回路徑是否是一個絕對路徑。 ## func [Abs](https://github.com/golang/go/blob/master/src/path/filepath/path.go#L233 "View Source") ``` func Abs(path string) (string, error) ``` Abs函數返回path代表的絕對路徑,如果path不是絕對路徑,會加入當前工作目錄以使之成為絕對路徑。因為硬鏈接的存在,不能保證返回的絕對路徑是唯一指向該地址的絕對路徑。 ## func [Rel](https://github.com/golang/go/blob/master/src/path/filepath/path.go#L251 "View Source") ``` func Rel(basepath, targpath string) (string, error) ``` Rel函數返回一個相對路徑,將basepath和該路徑用路徑分隔符連起來的新路徑在詞法上等價于targpath。也就是說,Join(basepath, Rel(basepath, targpath))等價于targpath本身。如果成功執行,返回值總是相對于basepath的,即使basepath和targpath沒有共享的路徑元素。如果兩個參數一個是相對路徑而另一個是絕對路徑,或者targpath無法表示為相對于basepath的路徑,將返回錯誤。 Example ``` paths := []string{ "/a/b/c", "/b/c", "./b/c", } base := "/a" fmt.Println("On Unix:") for _, p := range paths { rel, err := filepath.Rel(base, p) fmt.Printf("%q: %q %v\n", p, rel, err) } ``` Output: ``` On Unix: "/a/b/c": "b/c" <nil> "/b/c": "../b/c" <nil> "./b/c": "" Rel: can't make b/c relative to /a ``` ## func [SplitList](https://github.com/golang/go/blob/master/src/path/filepath/path.go#L178 "View Source") ``` func SplitList(path string) []string ``` 將PATH或GOPATH等環境變量里的多個路徑分割開(這些路徑被OS特定的表分隔符連接起來)。與strings.Split函數的不同之處是:對"",SplitList返回[]string{},而strings.Split返回[]string{""}。 Example ``` fmt.Println("On Unix:", filepath.SplitList("/a/b/c:/usr/bin")) ``` Output: ``` On Unix: [/a/b/c /usr/bin] ``` ## func [Split](https://github.com/golang/go/blob/master/src/path/filepath/path.go#L187 "View Source") ``` func Split(path string) (dir, file string) ``` Split函數將路徑從最后一個路徑分隔符后面位置分隔為兩個部分(dir和file)并返回。如果路徑中沒有路徑分隔符,函數返回值dir會設為空字符串,file會設為path。兩個返回值滿足path == dir+file。 ## func [Join](https://github.com/golang/go/blob/master/src/path/filepath/path.go#L199 "View Source") ``` func Join(elem ...string) string ``` Join函數可以將任意數量的路徑元素放入一個單一路徑里,會根據需要添加路徑分隔符。結果是經過簡化的,所有的空字符串元素會被忽略。 ## func [FromSlash](https://github.com/golang/go/blob/master/src/path/filepath/path.go#L168 "View Source") ``` func FromSlash(path string) string ``` FromSlash函數將path中的斜杠('/')替換為路徑分隔符并返回替換結果,多個斜杠會替換為多個路徑分隔符。 ## func [ToSlash](https://github.com/golang/go/blob/master/src/path/filepath/path.go#L158 "View Source") ``` func ToSlash(path string) string ``` ToSlash函數將path中的路徑分隔符替換為斜杠('/')并返回替換結果,多個路徑分隔符會替換為多個斜杠。 ## func [VolumeName](https://github.com/golang/go/blob/master/src/path/filepath/path.go#L465 "View Source") ``` func VolumeName(path string) (v string) ``` VolumeName函數返回最前面的卷名。如Windows系統里提供參數"C:\foo\bar"會返回"C:";Unix/linux系統的"\\host\share\foo"會返回"\\host\share";其他平臺會返回""。 ## func [Dir](https://github.com/golang/go/blob/master/src/path/filepath/path.go#L444 "View Source") ``` func Dir(path string) string ``` Dir返回路徑除去最后一個路徑元素的部分,即該路徑最后一個元素所在的目錄。在使用Split去掉最后一個元素后,會簡化路徑并去掉末尾的斜杠。如果路徑是空字符串,會返回".";如果路徑由1到多個路徑分隔符后跟0到多個非路徑分隔符字符組成,會返回單個路徑分隔符;其他任何情況下都不會返回以路徑分隔符結尾的路徑。 ## func [Base](https://github.com/golang/go/blob/master/src/path/filepath/path.go#L413 "View Source") ``` func Base(path string) string ``` Base函數返回路徑的最后一個元素。在提取元素前會求掉末尾的路徑分隔符。如果路徑是"",會返回".";如果路徑是只有一個斜桿構成,會返回單個路徑分隔符。 ## func [Ext](https://github.com/golang/go/blob/master/src/path/filepath/path.go#L212 "View Source") ``` func Ext(path string) string ``` Ext函數返回path文件擴展名。返回值是路徑最后一個路徑元素的最后一個'.'起始的后綴(包括'.')。如果該元素沒有'.'會返回空字符串。 ## func [Clean](https://github.com/golang/go/blob/master/src/path/filepath/path.go#L81 "View Source") ``` func Clean(path string) string ``` Clean函數通過單純的詞法操作返回和path代表同一地址的最短路徑。 它會不斷的依次應用如下的規則,直到不能再進行任何處理: ``` 1\. 將連續的多個路徑分隔符替換為單個路徑分隔符 2\. 剔除每一個.路徑名元素(代表當前目錄) 3\. 剔除每一個路徑內的..路徑名元素(代表父目錄)和它前面的非..路徑名元素 4\. 剔除開始一個根路徑的..路徑名元素,即將路徑開始處的"/.."替換為"/"(假設路徑分隔符是'/') ``` 返回的路徑只有其代表一個根地址時才以路徑分隔符結尾,如Unix的"/"或Windows的`C:\`。 如果處理的結果是空字符串,Clean會返回"."。參見[http://plan9.bell-labs.com/sys/doc/lexnames.html](http://plan9.bell-labs.com/sys/doc/lexnames.html) ## func [EvalSymlinks](https://github.com/golang/go/blob/master/src/path/filepath/path.go#L225 "View Source") ``` func EvalSymlinks(path string) (string, error) ``` EvalSymlinks函數返回path指向的符號鏈接(軟鏈接)所包含的路徑。如果path和返回值都是相對路徑,會相對于當前目錄;除非兩個路徑其中一個是絕對路徑。 ## func [Match](https://github.com/golang/go/blob/master/src/path/filepath/match.go#L44 "View Source") ``` func Match(pattern, name string) (matched bool, err error) ``` Match returns true if name matches the shell file name pattern. The pattern syntax is: ``` 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。 Windows系統中,不能進行轉義:'\\'被視為路徑分隔符。 ## func [Glob](https://github.com/golang/go/blob/master/src/path/filepath/match.go#L231 "View Source") ``` func Glob(pattern string) (matches []string, err error) ``` Glob函數返回所有匹配模式匹配字符串pattern的文件或者nil(如果沒有匹配的文件)。pattern的語法和Match函數相同。pattern可以描述多層的名字,如/usr/*/bin/ed(假設路徑分隔符是'/')。 ## type [WalkFunc](https://github.com/golang/go/blob/master/src/path/filepath/path.go#L337 "View Source") ``` type WalkFunc func(path string, info os.FileInfo, err error) error ``` Walk函數對每一個文件/目錄都會調用WalkFunc函數類型值。調用時path參數會包含Walk的root參數作為前綴;就是說,如果Walk函數的root為"dir",該目錄下有文件"a",將會使用"dir/a"調用walkFn參數。walkFn參數被調用時的info參數是path指定的地址(文件/目錄)的文件信息,類型為os.FileInfo。 如果遍歷path指定的文件或目錄時出現了問題,傳入的參數err會描述該問題,WalkFunc類型函數可以決定如何去處理該錯誤(Walk函數將不會深入該目錄);如果該函數返回一個錯誤,Walk函數的執行會中止;只有一個例外,如果Walk的walkFn返回值是SkipDir,將會跳過該目錄的內容而Walk函數照常執行處理下一個文件。 ## func [Walk](https://github.com/golang/go/blob/master/src/path/filepath/path.go#L385 "View Source") ``` func Walk(root string, walkFn WalkFunc) error ``` Walk函數會遍歷root指定的目錄下的文件樹,對每一個該文件樹中的目錄和文件都會調用walkFn,包括root自身。所有訪問文件/目錄時遇到的錯誤都會傳遞給walkFn過濾。文件是按詞法順序遍歷的,這讓輸出更漂亮,但也導致處理非常大的目錄時效率會降低。Walk函數不會遍歷文件樹中的符號鏈接(快捷方式)文件包含的路徑。 ## func [HasPrefix](https://github.com/golang/go/blob/master/src/path/filepath/path_unix.go#L23 "View Source") ``` func HasPrefix(p, prefix string) bool ``` HasPrefix函數出于歷史兼容問題保留,不應被使用。
                  <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>

                              哎呀哎呀视频在线观看