| 1 |
# filepathx |
| 2 |
|
| 3 |
> A small `filepath` extension library that supports double star globbling. |
| 4 |
|
| 5 |
## Documentation |
| 6 |
|
| 7 |
GoDoc: <https://pkg.go.dev/github.com/yargevad/filepathx> |
| 8 |
|
| 9 |
## Install |
| 10 |
|
| 11 |
```bash |
| 12 |
go get github.com/yargevad/filepathx |
| 13 |
``` |
| 14 |
|
| 15 |
## Usage Example |
| 16 |
|
| 17 |
You can use `a/**/*.*` to match everything under the `a` directory |
| 18 |
that contains a dot, like so: |
| 19 |
|
| 20 |
```go |
| 21 |
package main |
| 22 |
|
| 23 |
import ( |
| 24 |
"fmt" |
| 25 |
"os" |
| 26 |
|
| 27 |
"github.com/yargevad/filepathx" |
| 28 |
) |
| 29 |
|
| 30 |
func main() { |
| 31 |
if 2 != len(os.Args) { |
| 32 |
fmt.Println(len(os.Args), os.Args) |
| 33 |
fmt.Fprintf(os.Stderr, "Usage: go build example/find/*.go; ./find <pattern>\n") |
| 34 |
os.Exit(1) |
| 35 |
return |
| 36 |
} |
| 37 |
pattern := os.Args[1] |
| 38 |
|
| 39 |
matches, err := filepathx.Glob(pattern) |
| 40 |
if err != nil { |
| 41 |
panic(err) |
| 42 |
} |
| 43 |
|
| 44 |
for _, match := range matches { |
| 45 |
fmt.Printf("MATCH: [%v]\n", match) |
| 46 |
} |
| 47 |
} |
| 48 |
``` |
| 49 |
|
| 50 |
Given this directory structure: |
| 51 |
|
| 52 |
```bash |
| 53 |
find a |
| 54 |
``` |
| 55 |
|
| 56 |
```txt |
| 57 |
a |
| 58 |
a/b |
| 59 |
a/b/c.d |
| 60 |
a/b/c.d/e.f |
| 61 |
``` |
| 62 |
|
| 63 |
This will be the output: |
| 64 |
|
| 65 |
```bash |
| 66 |
go build example/find/*.go |
| 67 |
./find 'a/**/*.*' |
| 68 |
``` |
| 69 |
|
| 70 |
```txt |
| 71 |
MATCH: [a/b/c.d] |
| 72 |
MATCH: [a/b/c.d/e.f] |
| 73 |
``` |