Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. neueste Datei im Verzeichnis ermitteln

    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

    neueste Datei im Verzeichnis ermitteln

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

      Guten Morgen,

      mein System: iob auf win10 Rechner

      was will ich:
      Ich möchte die neueste Datei auf dem Laufwerk, z.B. c:\test ermitteln.

      Also per Script:

      • Dateien ermitteln
      • neueste Datei - Namen ermittlen.

      Hat jemand mal einen Script-Schnipsel für mich.

      mfg

      liv-in-sky 1 Reply Last reply Reply Quote 0
      • liv-in-sky
        liv-in-sky @bahnuhr last edited by

        @bahnuhr

        habe damit die datei gefunden

        var path = require('path');
        var fs = require('fs');
        
        var getMostRecent = function (dir, cb) {
        	var dir = path.resolve(dir);
        	var files = fs.readdir(dir, function (err, files) {
        		var sorted = files.map(function(v) {
        			var filepath = path.resolve(dir, v);
        			return {
        				name:v,
        				time:fs.statSync(filepath).mtime.getTime()
        			}; 
        		})
        		.sort(function(a, b) { return b.time - a.time; })
        		.map(function(v) { return v.name; });
        
        		if (sorted.length > 0) {
        			cb(null, sorted[0]);
        		} else {
        			cb('Y U NO have files in this dir?');
        		}
        	})
        }
        
        getMostRecent('/Daten', function (err, recent) {
        	if (err) console.error(err);
        	console.log(recent);
        });
        

        in zeile 25 ist das directory (/Daten) (linux) eingegeben

        vielleicht hilft es dir weiter

        Image 2.png

        1 Reply Last reply Reply Quote 1
        • bahnuhr
          bahnuhr Forum Testing Most Active last edited by

          @liv-in-sky

          Danke dir, klappt super.
          So machts Spaß.

          liv-in-sky 1 Reply Last reply Reply Quote 0
          • liv-in-sky
            liv-in-sky @bahnuhr last edited by

            @bahnuhr cool - ist aus github geklaut 🙂

            bahnuhr 1 Reply Last reply Reply Quote 0
            • bahnuhr
              bahnuhr Forum Testing Most Active @liv-in-sky last edited by

              @liv-in-sky sagte in neueste Datei im Verzeichnis ermitteln:

              @bahnuhr cool - ist aus github geklaut 🙂

              Ich hab ja auch schon ein bisschen gegoogelt. Aber halt nichts so richtig gefunden.

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

              Support us

              ioBroker
              Community Adapters
              Donate

              375
              Online

              31.8k
              Users

              80.0k
              Topics

              1.3m
              Posts

              2
              5
              293
              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