Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Braces for file extensions giving me a difficult time. #453

Closed
stuartambient opened this issue Aug 12, 2024 · 5 comments
Closed

Braces for file extensions giving me a difficult time. #453

stuartambient opened this issue Aug 12, 2024 · 5 comments

Comments

@stuartambient
Copy link

stuartambient commented Aug 12, 2024

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

@75lb
Copy link

75lb commented Aug 30, 2024

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.

@stuartambient
Copy link
Author

stuartambient commented Aug 30, 2024

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.

@mrmlnc
Copy link
Owner

mrmlnc commented Nov 23, 2024

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.

@stuartambient
Copy link
Author

stuartambient commented Nov 23, 2024

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.

@stuartambient
Copy link
Author

Closing as it turned out to be user error on my part. My apologies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants