go>> file>> 返回
项目作者: spiegel-im-spiegel

项目描述 :
Extend filepath.Glob function
高级语言: Go
项目地址: git://github.com/spiegel-im-spiegel/file.git
创建时间: 2019-10-26T17:37:59Z
项目社区:https://github.com/spiegel-im-spiegel/file

开源协议:MIT License

下载


file — Extend filepath.Glob function

Build Status
GitHub license
GitHub release

Usage

Search with **/ wildcard (match all directories recursively).

  1. matches, err := file.Glob("**/*.[ch]")
  2. if err != nil {
  3. fmt.Fprintf(os.Stderr, "%+v\n", err)
  4. return
  5. }
  6. for _, path := range matches {
  7. fmt.Println(path)
  8. }
  9. // Output:
  10. // testdata/include/source.h
  11. // testdata/source.c

Glob with context.Context

  1. matches, err := file.GlobWithContext(context.Background(), "**/*.[ch]")
  2. if err != nil {
  3. fmt.Fprintf(os.Stderr, "%+v\n", err)
  4. return
  5. }
  6. for _, path := range matches {
  7. fmt.Println(path)
  8. }
  9. // Output:
  10. // testdata/include/source.h
  11. // testdata/source.c

Glob with flags

  1. matches, err := file.Glob("**/*.[ch]", file.WithFlags(file.StdFlags|file.AbsolutePath))
  2. if err != nil {
  3. fmt.Fprintf(os.Stderr, "%+v\n", err)
  4. return
  5. }
  6. for _, path := range matches {
  7. fmt.Println(path)
  8. }
  9. // Output:
  10. // /home/username/go/src/github.com/spiegel-im-spiegel/file/testdata/include/source.h
  11. // /home/username/go/src/github.com/spiegel-im-spiegel/file/testdata/source.c
Flag Note
ContainsFile contains file
ContainsDir contains directory
SeparatorSlash use slash character for separator character in path
AbsolutePath output absolute representation of path
StdFlags `ContainsFile \ ContainsDir` (default)