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

[Bug]: @capacitor/filesystem - readdir won't read files from dir #7784

Closed
1 of 3 tasks
biast12 opened this issue Dec 1, 2024 · 3 comments
Closed
1 of 3 tasks

[Bug]: @capacitor/filesystem - readdir won't read files from dir #7784

biast12 opened this issue Dec 1, 2024 · 3 comments
Labels
needs reproduction needs reproducible example to illustrate the issue

Comments

@biast12
Copy link

biast12 commented Dec 1, 2024

Capacitor Version

Latest Dependencies:

@capacitor/cli: 6.2.0
@capacitor/core: 6.2.0
@capacitor/android: 6.2.0
@capacitor/ios: 6.2.0

Installed Dependencies:

@capacitor/cli: 6.1.2
@capacitor/core: 6.1.2
@capacitor/android: 6.1.2
@capacitor/ios: 6.1.2

[success] Android looking great! 👌

Other API Details

npm --version output: 10.9.1
node --version output: v21.6.0

Platforms Affected

  • iOS
  • Android
  • Web

Current Behavior

Filesystem.readdir does not output the files within the folder given (it gives an empty array)

When dirpath is "" / not a dir does it give an array with 49 objects where the "langs" dir is listed

The folder structure:

  • ROOT/
    • DATA/
      • langs/
        • en.json
        • da.json
        • de.json

Here is my function

const importLanguages = async () => {
    try {
      const dirpath = "langs";
      const languageFiles = await Filesystem.readdir({
        path: dirpath,
        directory: Directory.Data,
      });

      console.log(languageFiles);

      const loadedLanguages: { [key: string]: string } = {};

      for (const file of languageFiles.files) {
        const filePath = file.uri;
        const fileContent = await Filesystem.readFile({
          path: filePath,
          directory: Directory.Data,
        });
        const langModule = JSON.parse(fileContent.data as string);
        const langCode = file.name.match(/(\w+)\.json$/)?.[1];
        if (langCode) {
          if (langModule.lang) {
            loadedLanguages[langCode] = langModule.lang;
          } else {
            loadedLanguages[langCode] =
              t("pages.settings.general.lang_missing_key") ||
              "Lang key missing";
          }
        }
      }

      const sortedLanguages = Object.fromEntries(
        Object.entries(loadedLanguages).sort(([, a], [, b]) => {
          if (a === "English") return -1;
          if (b === "English") return 1;
          return a.localeCompare(b);
        })
      );

      setLanguages(sortedLanguages);
    } catch (err) {
      console.error("Error reading language files", err);
    }
  };

Expected Behavior

It should / is expected to list out the en.json, da.json and de.json files within the langs dir, they're in there and it can find the langs dir

Project Reproduction

It's a private repository, so i can't share a link really

Additional Information

No response

@biast12 biast12 added the triage label Dec 1, 2024
@jcesarmobile jcesarmobile added the needs reproduction needs reproducible example to illustrate the issue label Dec 3, 2024
Copy link

ionitron-bot bot commented Dec 3, 2024

This issue needs more information before it can be addressed. In particular, the reporter needs to provide a minimal sample app that demonstrates the issue. If no sample app is provided within 15 days, the issue will be closed.
Please see the Contributing Guide for how to create a Sample App.
Thanks! Ionitron 💙

@ionitron-bot ionitron-bot bot removed the triage label Dec 3, 2024
@Ionitron Ionitron added needs reply needs reply from the user and removed needs reply needs reply from the user labels Dec 3, 2024
@jcesarmobile jcesarmobile added the needs reply needs reply from the user label Dec 3, 2024
@Ionitron
Copy link
Collaborator

It looks like this issue didn't get the information it needed, so I'll close it for now. If I made a mistake, sorry! I am just a bot.

Have a great day!
Ionitron 💙

@Ionitron Ionitron removed the needs reply needs reply from the user label Dec 19, 2024
Copy link

ionitron-bot bot commented Jan 18, 2025

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Jan 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs reproduction needs reproducible example to illustrate the issue
Projects
None yet
Development

No branches or pull requests

3 participants