Glob documentation (I'll refer to it):
- * Matches 0 or more characters in a single path portion
- ? Matches 1 character
- [...] Matches a range of characters, similar to a RegExp range. If the first character of the range is - ! or ^ then it matches any character not in the range.
- !(pattern|pattern|pattern) Matches anything that does not match any of the patterns provided.
- ?(pattern|pattern|pattern) Matches zero or one occurrence of the patterns provided.
- +(pattern|pattern|pattern) Matches one or more occurrences of the patterns provided.
- *(a|b|c) Matches zero or more occurrences of the patterns provided
- @(pattern|pat*|pat?erN) Matches exactly one of the patterns provided
- ** If a "globstar" is alone in a path portion, then it matches zero or more directories and subdirectories searching for matches.
**
should do it.[^_]*
..pug
will will be enough, but .+(pug)
allow to scale the solution to n
filename extensions like .+(pug|haml)
./Pages/Open/**/[^_]*.+(pug)
The EntryPoint.pug
was excluded, however it's name does not begin from underscore.
🌎 Fiddle
All that I know is "globstar matches zero or more directories and subdirectories searching for matches" and "[^_]
" excludes underscore. Looks like it's not enough to build the correct solution. Below solution in intuitive and does not work.
/Pages/Open/[^_]**/*.+(pug)
🌎 Fiddle
Can we reach this effect just by combining the solution for files and directories?
Use ignore option of glob to exclude directories and files starting from character underscore
var glob = require('glob');
glob("**/*",{"ignore":['**/_**.pug', "**/_**/**"]}, function (err, files) {
console.log(files);
})
// Output
[
'Pages',
'Pages/Open',
'Pages/Open/EntryPoint.pug',
'Pages/Open/Top',
'Pages/Open/Top/EntryPoint.pug',
'Pages/Open/Top/SubDirectory1',
'Pages/Open/Top/SubDirectory1/NonPartial.pug',
'test.js'
]
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