Braces for file extensions giving me a difficult time.
Environment
Windows 10, Node 20.15, Fast-glob 3.3.2, Electron 20.x.
Actual behavior
using brace expansion to find graphic files in different folders fails. It will work just using individual extension for the run
Expected behavior
finding graphic files specified in the braces I've included
Steps to reproduce
IDK really, I am using FG is 3 other scripts in this project and it works fine using similar code.
Code sample
// Paste your code here.
function escapeSpecialChars(path) {
return path.replace(/[\[\]\(\)\{\}]/g, '\\$&');
}
const options = {
caseSensitiveMatch: false,
suppressErrors: true,
dot: true
};
function searchCover(folder) {
const escapedPath = escapeSpecialChars(folder);
const cover = fg.sync(`${escapedPath}/**/*.{jpg, jpeg, png, webp}`, options);
if (cover.length > 0) {
return cover[0];
}
return;
}
const updateCoversLink = async () => {
const foundCovers = [];
const allAlbumsRootFolder = await getAlbumsNullImg();
const covers = await Promise.all(
allAlbumsRootFolder.map(async (folder) => ({
fullpath: folder.fullpath,
img: await searchCover(folder.fullpath)
}))
);
covers.forEach((cov) => console.log(cov));
Also /*.{jpg,jpeg,png,webp} fails as well.
What works is
const cover = fg.sync(${escapedPath}/**/*.jpg, options);
edit: meant to add that I can do this - fg.sync(`${escapedPath}/* which returns everything in the directory, and I guess that might be an option if I have no choice
Could you simplify the reproduction case down to a single invocation example that fails, also sharing the exception thrown? E.g.
fg.sync('/something/**/*.{jpg, jpeg, png, webp}', { optionA: true, optionB: 'whatever' });
// throws SomethingError
People, including the readers, don't have time to decipher your code.. Cheers.
Could you simplify the reproduction case down to a single invocation example that fails, also sharing the exception thrown? E.g.
People, including the readers, don't have time to decipher your code.. Cheers.
There is no exception thrown hence no failure, just a failure to return results if I include the extensions in braces. Simplified - const cover = fg.sync(${escapedPath}/**/*.{jpg, jpeg, png, webp}, options);, returns empty array.
Unfortunately, I cannot reproduce the problem, or I am doing it incorrectly, since there is no information about the directory structure in the issue. Please provide a minimal reproduction code.
since there is no information about the directory structure in the issue.
Sorry, not following on the question of directory structure. It's on Windows, so NTFS. They are directories that have 1 ... many files and some of those files are graphic files. Directory names contain spaces, hypens and text in brackets or parentheses. This is an example of a directory name -
F:/Music/36 and zakè - Stasis Sounds for Long-Distance Space Travel (2020) {PITP39, WEB, 24-44.1} [FLAC]
Give me a few days and I'll try to give you some minimal code.
Closing as it turned out to be user error on my part. My apologies.