119

I have this path in my react gulpfile:

var path = {
  HTML: 'src/index.html',
  ALL: ['src/js/*.js', 'src/js/**/*.js', 'src/index.html'],
  JS: ['src/js/*.js', 'src/js/**/*.js'],
  MINIFIED_OUT: 'build.min.js',
  DEST_SRC: 'dist/src',
  DEST_BUILD: 'dist/build',
  DEST: 'dist'
};

What is the double glob character?

I know what the single glob is... but what is the double? single glob

Squidly
  • 2,707
  • 19
  • 43
Jwan622
  • 11,015
  • 21
  • 88
  • 181

4 Answers4

156

It's almost the same as the single asterisk but may consist of multiple directory levels.

In other words, while /x/*/y will match entries like:

/x/a/y
/x/b/y

and so on (with only one directory level in the wildcard section), the double asterisk /x/**/y will also match things like:

/x/any/number/of/levels/y

with the concept of "any number of levels" also including zero (in other words, /x/**/y will match /x/y as one of its choices).


As an aside, as much as I hate to credit the mainframe with anything, I believe this has been used since the earlist days of MVS to allow selection of datasets at multiple levels :-)

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • 2
    This makes no sense. If * denotes 0 or more characters, then that pattern could potentially match /x//y, which is nonsensical. What you're really saying is "any number of characters, followed by any number of characters". Isn't that just... oh, I don't know... *any number of characters*??? – Aleksandr Hovhannisyan Aug 27 '18 at 01:21
  • 10
    @AleksandrH, no, this isn't a regex in the normal sense: there's no matching of *characters,* only directory names. This is *specifically* for hierarchical file systems. On your first point, if empty directory names were allowed, `/x//y` would be perfectly valid. I've never seen a file system that allows this however. On your second point, the `*` means match "any directory name, *one level only"* (so won't go beyond the next `/` divider) while `**` means "match *any number of levels* with any directory name at each level" (can cross over as many `/` dividers as needed). – paxdiablo Aug 27 '18 at 01:44
  • 16
    It's worth noting that for `/x/**/y/`, `/x/y/` is also included, which is neat. – Yassine Imounachen Mar 18 '19 at 18:09
  • @YassineImounachen yes. There are more non-obvious nuances. For the visually inclined, see https://stackoverflow.com/a/66744400/8910547 – Inigo Mar 22 '21 at 12:32
35

** matches any character including a forward-slash /
* matches any character except a forward-slash (to match just the file or directory name)

Simon East
  • 55,742
  • 17
  • 139
  • 133
Thomas S.
  • 5,804
  • 5
  • 37
  • 72
  • 4
    This is close but not perfect. `x/**` will match `x`. See https://metacpan.org/pod/distribution/File-Globstar/lib/File/Globstar.pod – Inigo Mar 22 '21 at 08:44
  • 3
    For people who found this discussion while looking for info on the python glob function: the glob function is working as you describe. "/x/**/y" doesn't match "/x/y" – programort Mar 09 '22 at 19:07
29

It's usually used to indicate any number of subdirectories. So

src/js/**/*.js

Would match

src/js/files/*.js
src/js/more-files/*.js

etc
etc
Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
Sean
  • 60,939
  • 11
  • 97
  • 136
6

Like Grunt, the double ** is saying, "Look in all the subfolders within js and for all of the .js files."

You can actually refer here for the same:

https://www.codefellows.org/blog/quick-intro-to-gulp-js

ShivangiBilora
  • 2,912
  • 4
  • 20
  • 27