Pure Nim library for matching file paths against Unix style glob patterns.
cf60c6f
) (#56 by @timotheecour)83bdafc
)Absolute notin options
)1ea34f9
)d9d1175
)ffd65d3
)1fa54df
), closes #29
633a87d
), closes #29
4a0d545
)This release was made possible through contributions by:
Thanks!
Greetings from v0.8.0
— a significant release that cleans up the API and provides several new features!
listGlob
removalThe seq
-returning proc listGlob
is also removed to encourage the use of the iterators walkGlob
or walkGlobKinds
. It's also easy enough to get a seq
from these using sequtils.toSeq
from Nim's stdlib that it was mostly unnecessary.
GlobOption
flagsOptions (like includeDirs
or includeHidden
) are no longer provided as individual boolean parameters and are instead part of a set[GlobOption]
, the default for which is exported as defaultGlobOptions
. You can alter this like you would any other set using unions and intersections:
import glob
import sequtils
const options = defaultGlobOptions + {Hidden, FollowLinks} - {Files}
echo toSeq(walkGlob("src", options = options))
# or replace the default options completely
echo toSeq(walkGlob("src", options = {Hidden}))
# @[... only hidden files under src/ ...]
Several of these flags are equivalent to parameters in the <=0.7.0
API, but a few of them are new:
pre-0.8.0 |
0.8.0 flag |
meaning |
---|---|---|
relative = false |
GlobOption.Absolue |
yield paths as absolute rather than relative to root |
expandDirs = false |
GlobOption.NoExpandDirs |
if pattern is a directory don't treat it as <dir>/**/* |
includeHidden = true |
GlobOption.Hidden |
yield hidden files or directories |
includeDirs = true |
GlobOption.Directories |
yield directories |
N/A | GlobOption.IgnoreCase |
matching will ignore case differences |
N/A | GlobOption.Files |
yield files |
N/A | GlobOption.DirLinks |
yield links to directories |
N/A | GlobOption.FileLinks |
yield links to files |
N/A | GlobOption.FollowLinks |
recurse into directories through links |
So this new options set allows for more granular things like only returning links:
for path in walkGlob(".", options = {FileLinks, DirLinks}):
# only links!
discard
Patterns can now be made case-insensitive, which works even on platforms with case-sensitive filesystems. The defaultGlobOptions
on Windows will include GlobOption.IgnoreCase
and patterns created on Windows will be case-insensitive by default.
When the options flags aren't enough, you can do a lot more with the optional filterYield
or filterDescend
procs to decide what gets yielded and what directories are traversed.
type
FilterDescend* = (path: string) -> bool
FilterYield* = (path: string, kind: PathComponent) -> bool
filterDescend
is called whenever the iterator comes across a directory that is about to be recursed into. If you return false, the iterator will abandon that recursion. Any path received by a filterDescend
proc is guaranteed to be a directory or a link to a directory.
filterYield
is called whenever an item (file, directory, or link) is about to be yielded. If you return false, the iterator will not yield the item.
listGlob
has been removed to encourage the use of iterators. sequtils.toSeq
from Nim's stdlib can be used to convert the iterators to seqsGlobResult
has been renamed GlobEntry
fe17bdd
)76e1582
)GlobResult
to GlobEntry
(34fa6f3
)os.PathComponent
for ease of use (de74aff
)8ef605b
)0cdb00f
)includeHidden == false
(#14) (b6de2fd
)cfabbea
)