Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Glob ¶
func Glob(pattern string, opts ...GlobOptFunc) ([]string, error)
Glob returns the names of all files matching pattern. This function expands filepath.Glob
Example ¶
package main
import (
"fmt"
"os"
"github.com/spiegel-im-spiegel/file"
)
func main() {
matches, err := file.Glob("**/*.[ch]", file.WithFlags(file.StdFlags|file.SeparatorSlash))
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
func GlobWithContext ¶
GlobWithContext returns the names of all files matching pattern with context.Context.
Example ¶
package main
import (
"context"
"fmt"
"os"
"github.com/spiegel-im-spiegel/file"
)
func main() {
matches, err := file.GlobWithContext(context.Background(), "**/*.[ch]", file.WithFlags(file.StdFlags|file.SeparatorSlash))
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
Types ¶
type Flags ¶
type Flags uint
Flags is type of operation flag in Glob() function.
const ( ContainsFile Flags = 1 << iota //contains file ContainsDir //contains directory SeparatorSlash //use slash ('/') character for separator character in path AbsolutePath //output absolute representation of path StdFlags = ContainsFile | ContainsDir )
Operation flag in Glob() function.
func (Flags) AbsolutePath ¶
AbsolutePath returns status of AbsolutePath flag.
func (Flags) ContainsDir ¶
ContainsDir returns status of ContainsDir flag.
func (Flags) ContainsFile ¶
ContainsFile returns status of ContainsFile flag.
func (Flags) SeparatorSlash ¶
SeparatorSlash returns status of SeparatorSlash flag.
type GlobOptFunc ¶
type GlobOptFunc func(*glob)
GlobOptFunc is self-referential function for functional options pattern.
func WithFlags ¶
func WithFlags(f Flags) GlobOptFunc
WithFlags returns function for setting glob instance.
Click to show internal directories.
Click to hide internal directories.