Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. ioBroker Allgemein
    4. Javascript: Probleme mit readdir : feature oder bug?

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    Javascript: Probleme mit readdir : feature oder bug?

    This topic has been deleted. Only users with topic management privileges can see it.
    • E
      ente34 last edited by

      Ich habe alle Adapter von stable auf latest ge-updated.
      Dabei ist mir aufgefallen, dass in Scripts das 'readdir' Fehler wirft

      const fs = require('fs');
      const util = require('util');
      const my_readdir = util.promisify(fs.readdir);
      
      const searchDir = '/tmp';
      
      async function FindFile(dir) {
          let rc = '';
          //console.log('### '+dir);
          try {
              let files = [];
              files = await my_readdir(dir);
              for (let file of files) {
                  let fullpath = dir + '/' + file;
                  rc = fullpath;
              }
          } catch (e) {
              console.log(e);
          } finally {
              return rc;
          }
      }
      
      function execPromise(command) {
          return new Promise(function(resolve, reject) {
              exec(command, (error, stdout, stderr) => {
                  if (error) {
                      //console.log(stderr);
                      reject(error);
                      return;
                  }
                  resolve(stdout.trim());
              });
          });
      }
      
      
      
      try {
          let result = FindFile(searchDir);
          //let result = await execPromise(`find ${searchDir} -type f `);
          log(result);
      } catch (e) {
          console.error(e.message);
      }
      

      Es gibt die folgende log-Meldung:

      javascript.0
      	2025-07-27 11:42:01.749	info	script.js.Test.readdir: TypeError: Cannot read properties of undefined (reading 'ProtectFs') at readdir (/opt/iobroker/node_modules/iobroker.javascript/src/lib/protectFs.ts:625:14) at node:internal/util:438:7 at new Promise (<anonymous>) at readdir (node:internal/util:424:12) at FindFile (script.js.Test.readdir:114:23) at script.js.Test.readdir:142:18 at script.js.Test.readdir:152:3 at Script.runInContext (node:vm:149:12) at Script.runInNewContext (node:vm:154:17) at JavaScript.execute (/opt/iobroker/node_modules/iobroker.javascript/src/main.ts:2203:27)
      

      Die Alternative mit exec funktioniert.

      Homoran haus-automatisierung 2 Replies Last reply Reply Quote 0
      • Homoran
        Homoran Global Moderator Administrators @ente34 last edited by

        @ente34 sagte in Javascript: Probleme mit readdir : feature oder bug?:

        Ich habe alle Adapter von stable auf latest ge-updated.

        warum denn das?
        Damit hast du jetzt überall Betaversionen, die jede für sich noch Bugs enthalten kann.

        Zu jedem Adapter gibt es daher Betatester Threads im Forum, oder Issuetracking auf Github

        E 1 Reply Last reply Reply Quote 1
        • E
          ente34 @Homoran last edited by

          @homoran Alles klar, danke für den Hinweis!

          1 Reply Last reply Reply Quote 0
          • haus-automatisierung
            haus-automatisierung Developer Most Active @ente34 last edited by

            @ente34 sagte in Javascript: Probleme mit readdir : feature oder bug?:

            const my_readdir = util.promisify(fs.readdir);

            Dafür gibt es eigentlich fs/promises. https://nodejs.org/api/fs.html#fspromisesreaddirpath-options

            Im Adapter wird fs vom node core überschrieben, damit man in manche Verzeichnisse nicht manuell schreibt (wie iobroker-data/files). Mit einem einfachen Beispiel als Bug melden (bist ja Beta-Tester).

            E 1 Reply Last reply Reply Quote 0
            • E
              ente34 @haus-automatisierung last edited by

              @haus-automatisierung sagte in Javascript: Probleme mit readdir : feature oder bug?:

              @ente34 sagte in Javascript: Probleme mit readdir : feature oder bug?:

              const my_readdir = util.promisify(fs.readdir);

              Dafür gibt es eigentlich fs/promises. https://nodejs.org/api/fs.html#fspromisesreaddirpath-options

              Im Adapter wird fs vom node core überschrieben, damit man in manche Verzeichnisse nicht manuell schreibt (wie iobroker-data/files). Mit einem einfachen Beispiel als Bug melden (bist ja Beta-Tester).

              Danke für die schnelle Antwort!
              Wo genau melden, javascript-Adapter, js-controller, ...?

              haus-automatisierung 1 Reply Last reply Reply Quote 0
              • haus-automatisierung
                haus-automatisierung Developer Most Active @ente34 last edited by

                @ente34 sagte in Javascript: Probleme mit readdir : feature oder bug?:

                javascript-Adapter

                https://github.com/ioBroker/ioBroker.javascript/issues

                1 Reply Last reply Reply Quote 3
                • First post
                  Last post

                Support us

                ioBroker
                Community Adapters
                Donate
                FAQ Cloud / IOT
                HowTo: Node.js-Update
                HowTo: Backup/Restore
                Downloads
                BLOG

                538
                Online

                31.9k
                Users

                80.3k
                Topics

                1.3m
                Posts

                3
                6
                68
                Loading More Posts
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes
                Reply
                • Reply as topic
                Log in to reply
                Community
                Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                The ioBroker Community 2014-2023
                logo