How do I change / ** and / * in terms of directory navigation in Grunt?

It's pretty easy for you, but I cannot 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 / **" can mean: every file and folder inside A, and every file and folder directly inside every child that is directly inside A. (Basically, the extension of the / * operator that crosses one level deeper into the root folder ? aka "/ **" = "/ * / *")

My terminology "directly inside" may be wrong. It might be better to say "straight child" or something else, but you get the idea.

Then what does "A / ** / *" mean? Is it equal to "A / * / * / *"?

While this seems basic, it gets pretty confusing when I don't have a formal definition of operators.

I am currently using Javascript and am trying to modify a Grunt file. But I think these operators can appear in any context.

+3


source to share


2 answers


This behavior is not inherent in JavaScript and is not associated with any operators: as far as JavaScript is concerned, it is just a string.

The handling of such glob expansion is library / consumer specific. For gruntjs, it is presented in Grunt Globbing Patterns :

It is often impractical to specify all source file paths separately, which is why Grunt supports filename expansion (also known as globbing) through the built-in libraries node-glob and minimatch.

  • *

    matches any number of characters, but not /

  • **

    matches any number of characters, including /

    if it is the only one in the path

All most people need is that it foo/*.js

will match all files ending in .js in the foo / subdirectory, but foo/**/*.js

will match all files ending in .js in the foo / subdirectory and all its subdirectories.

As such (but consult your specific documentation!), It /**/

usually means "match any directory depth", but /*/

or /*

means "match one directory or part of a file".




The gruntjs documentation is a little vague on the specific mechanics **

in the standard template "/**/*.x"

, but referring to node-glob says:

If globstar ( **

) is the only one in the path portion, then it matches zero or more directories and subdirectories, looking for a match. It does not scan symbolic directories.

[.. The two-star character] is supported by bsdglob and bash 4.3, where it **

has a special meaning if it is the only one in the path. That is, it a/**/b

will correspond a/x/y/b

, but a/**b

it will not.

Using this knowledge, we have the equivalence (when used as a component of the path), A/**/f

with A/f

, A/*/f

, A/*/*/f

etc. for each number of intermediate directories.

+6


source


If you can see A/**/*

it means to recursively search all the paths down the tree for each folder in the folder A

. Look for basic linux style file commands for more information.



0


source







All Articles