This is quite an easy one for you guys, but I can't find a definitive/formal answer to this question.
Suppose we are in directory A. Then,
"A/* " probably means: Every file and folder directly inside A.
"A/** " then may mean: Every file and folder inside A, and every file and folder directly inside every child that is directly inside A. (Basically, an extension of /* operator that traverses one level deeper of the root folder? aka "/** " = "/* /* " )
My "directly inside" terminology might be wrong. May be its better to say "direct child" or something, but you get the idea.
Then, what does "A/**/* " mean? Is it equal to "A/* /* /* " ?
Although this seems basic, its quite confusing when I don't have a formal definition of the operators.
I'm currently using Javascript and trying to modify a Gruntfile. But I guess these operators may come up in any context.
This behavior is not intrinsic to JavaScript and is not related to any operators: as far as JavaScript is concerned, it is just a string.
The handling of such glob expansion is determined by the specific library/consumer. For gruntjs it is covered in Grunt Globbing Patterns:
It is often impractical to specify all source filepaths individually, so Grunt supports filename expansion (also know as globbing) via the built-in node-glob and minimatch libraries ..
*
matches any number of characters, but not/
**
matches any number of characters, including/
, as long as it's the only thing in a path partAll most people need to know is that
foo/*.js
will match all files ending with .js in the foo/ subdirectory, butfoo/**/*.js
will match all files ending with .js in the foo/ subdirectory and all of its subdirectories.
As such (but refer to the specific documentation!), /**/
generally means "match any depth of directories" and /*/
or /*
means "match a single directory or file part".
The gruntjs documentation is a bit vague on the specific mechanics of **
in the standard "/**/*.x"
pattern, but referring to node-glob says:
If a "globstar" (
**
) is alone in a path portion, then it matches zero or more directories and subdirectories searching for matches. It does not crawl symlinked directories.[.. The double-star character] is supported in the manner of bsdglob and bash 4.3, where
**
only has special significance if it is the only thing in a path part. That is,a/**/b
will matcha/x/y/b
, buta/**b
will not.
Using this knowledge we get the equivalency (when used as a path component), of A/**/f
with A/f
, A/*/f
, A/*/*/f
, etc for every number of intermediate directories.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With