shashi / FileTrees.jl

Parallel computing with a tree of files metaphor
http://shashi.biz/FileTrees.jl
Other
88 stars 6 forks source link

Tree predicates? #30

Open MichaelHatherly opened 4 years ago

MichaelHatherly commented 4 years ago

(I might have completely overlooked it if it's already implemented?)

I'd like to check whether a given path exists in a FileTree, such as

t = FileTree(".")
"my/file.ext" in t

Does anything like this currently exist? Or is there an idiomatic alternative that's reasonably efficient? There's the getindex methods that take globs or regex, but I'm just needing a Bool result given a path.

shashi commented 4 years ago

That's would be a really nice API addition! I agree it's super clunky to do that right now.

shashi commented 4 years ago

an easy way to do this would be:

!isempty(t[glob"my/file.ext"])
MichaelHatherly commented 4 years ago

With a glob it still throws an error if _glob_filter returns nothing:

https://github.com/shashi/FileTrees.jl/blob/3a26a5c4ad3a25e0ea5c427c6b65b1e351dc9ca5/src/patterns.jl#L5-L11

Should that method be returning an empty tree instead?

A couple of one-liner in methods could be added to bypass that nothing check I guess?

Base.in(g::GlobMatch, t::FileTree) = _glob_filter(t, name(t), g.pattern...) !== nothing
Base.in(p::PathLike, t::FileTree) = GlobMatch(string(p)) in t