Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. [gelöst] Userdata unterordner duplizieren

    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

    [gelöst] Userdata unterordner duplizieren

    This topic has been deleted. Only users with topic management privileges can see it.
    • CrunkFX
      CrunkFX Forum Testing last edited by CrunkFX

      Mahlzeit, Ich hab mir in Userdata für einen eigenen Gerätetyp eine Komplizierte Ordnerstruktur aufgebaut. Kann ich nun via Script alle unterordner duplizieren? Der Übergeordnete Ordner heißt "1" und würde dann für die weiteren Geräte um 1 erhöht.

      Wie mache ich das am einfachsten?

      MFG
      CrunkFX

      paul53 1 Reply Last reply Reply Quote 0
      • paul53
        paul53 @CrunkFX last edited by

        @CrunkFX
        Ich habe mal ein Script zum Erzeugen einer Userdata-Struktur abgewandelt, aber nicht getestet:

        // Kopieren von Datenpunkten
        // Pfade anpassen !
        const pathSrc = '0_userdata.0.1.'; // abschließenden Punkt angeben
        const pathDst = '0_userdata.0.2.';
        const idsSrc = $(pathSrc + '*');
        
        idsSrc.each(function(id, i) {
            let idDst = pathDst + id.substring(pathSrc.length);
            if(existsObject(idDst)) log('Datenpunkt ' + idDst + ' existiert bereits !', 'warn');
            else {
                let obj = getObject(id);
                setObject(idDst, obj, function (err) {
                    if (err) log('Cannot write object: ' + err)
                    else {
                        let init = null;
                        if(existsState(id)) init = getState(id).val;
                        else {
                            let common = obj.common;
                            if(common.def === undefined) {
                                if(common.type === 'number') init = 0;
                                if(common.type === 'boolean') init = false;
                                if(common.type === 'string') init = '';
                                if(common.type === 'array') init = [];
                            } else init = common.def;
                        }
                        setStateDelayed(idDst, init, true, 30 * i + 50);
                    }
                });
            }
        });
        
        CrunkFX 1 Reply Last reply Reply Quote 1
        • CrunkFX
          CrunkFX Forum Testing @paul53 last edited by

          @paul53 Funktioniert einwandfrei, Besten Dank!

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

          Support us

          ioBroker
          Community Adapters
          Donate

          968
          Online

          31.8k
          Users

          80.0k
          Topics

          1.3m
          Posts

          2
          3
          201
          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