/file

Extend filepath.Glob function

Primary LanguageGoMIT LicenseMIT

file -- Extend filepath.Glob function

Build Status GitHub license GitHub release

Usage

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

matches, err := file.Glob("**/*.[ch]")
if err != nil {
    fmt.Fprintf(os.Stderr, "%+v\n", err)
    return
}
for _, path := range matches {
    fmt.Println(path)
}
// Output:
// testdata/include/source.h
// testdata/source.c

Glob with context.Context

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

Glob with flags

matches, err := file.Glob("**/*.[ch]", file.WithFlags(file.StdFlags|file.AbsolutePath))
if err != nil {
    fmt.Fprintf(os.Stderr, "%+v\n", err)
    return
}
for _, path := range matches {
    fmt.Println(path)
}
// Output:
// /home/username/go/src/github.com/spiegel-im-spiegel/file/testdata/include/source.h
// /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)