Tuesday, 25 August 2020

Exclude files and/or folders recursively which name begins from certain symbol in NodeJS's Glob (on underscore example)

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.

Recursively exclude FILES which name begins from underscore

Solution attempt

  1. First we need to match zero or more directories (I suppose, it means "in this directory and below"). As far as I understood the documentation, ** should do it.
  2. Next we need to exclude the files which name begins from underscore. AFAIK it is [^_]*.
  3. The filename extension left. Maybe .pug will will be enough, but .+(pug) allow to scale the solution to n filename extensions like .+(pug|haml).
/Pages/Open/**/[^_]*.+(pug)

enter image description here

The EntryPoint.pug was excluded, however it's name does not begin from underscore.

🌎 Fiddle

Recursively exclude DIRECTORIES which name begins from underscore

Solution attempt

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)

enter image description here

🌎 Fiddle

Recursively exclude files AND directories which name begins from underscore

Can we reach this effect just by combining the solution for files and directories?



from Exclude files and/or folders recursively which name begins from certain symbol in NodeJS's Glob (on underscore example)

No comments:

Post a Comment