Can anyone please suggest how to add multiple file extensions with the glob.sync
method.
Something like:
const glob = require('glob');
let files = glob.sync(path + '**/*.(html|xhtml)');
Thank you :)
Can anyone please suggest how to add multiple file extensions with the glob.sync
method.
Something like:
const glob = require('glob');
let files = glob.sync(path + '**/*.(html|xhtml)');
Thank you :)
You can use this (which most shells support as well):
glob.sync(path + '**/*.{html,xhtml}')
Or this one:
glob.sync(path + '**/*.@(html|xhtml)')
EDIT: I initially also suggested this pattern:
glob.sync(path + '**/*.+(html|xhtml)')
However, this will also match files that have .htmlhtml
as extension (plus any other combination of html
and xhtml
, in single or multiple occurrences), which is incorrect.
@(PATTERN)
matches files that have PATTERN
in their name exactly once, +(PATTERN)
matches files that have PATTERN
in their name at least once (so my example of *.+(html|xhtml)
also matches files that end with .htmlhtml
, which is incorrect). –
Worcester © 2022 - 2024 — McMap. All rights reserved.