Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Programmsuchdatei in Java

    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

    UNSOLVED Programmsuchdatei in Java

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

      Ich möchte ein Dateisuchtool in Java erstellen, das sowohl unter Linux als auch unter Windows funktioniert. Ich bin mit Windows vertraut, aber ich bin nicht mit Linux vertraut. Diese Logik wird verwendet, um alle Discs in den Fenstern anzuzeigen.

      package test;
      
      import java.io.File;
      
      public class Test {
      public static void main(String[] args) {
          File[] drives = File.listRoots();
          String temp = "";
          for (int i = 0; i < drives.length; i++) {
              temp += drives[i];
          }
      
          String[] dir = temp.split("\\\\");
          for (int i = 0; i < dir.length; i++) {
              System.out.println(dir[i]);
      
          }
      }
      }
      

      Bei Verwendung in Windows zeigt der obige Code alle Roots wie c:, d: usw. an, aber bei Verwendung in Linux zeigt er nur / an. Ich verwende diese Argumentation auch, um eine bestimmte Datei in Windows zu finden.

      public void findFile(String name,File file)
      {
          File[] list = file.listFiles();
          if(list!=null)
          for (File fil : list)
          {
              if (fil.isDirectory())
              {
                  findFile(name,fil);
              }
              else if (name.equalsIgnoreCase(fil.getName()))
              {
                  System.out.println(fil.getParentFile());
              }
          }
      }
      

      Es funktioniert gut, aber meine Schwierigkeit besteht darin, herauszufinden, wie es unter Linux geht; Ich bin neu bei Linux und habe keine Ahnung, wie es geht, und mir läuft die Zeit davon; Jede Hilfe wäre sehr willkommen.

      Thomas Braun OliverIO 2 Replies Last reply Reply Quote 0
      • Thomas Braun
        Thomas Braun Most Active @jacusi last edited by

        @jacusi sagte in Programmsuchdatei in Java:

        alle Roots wie c:, d: usw. an, aber bei Verwendung in Linux zeigt er nur / an.

        Unter Linux ist / das Wurzelverzeichnis. Laufwerksbuchstaben gibt es ja da zum Glück nicht.

        1 Reply Last reply Reply Quote 1
        • OliverIO
          OliverIO @jacusi last edited by

          @jacusi
          Warum das Rad neu erfinden? Warum Java?
          Da reich doch die Shell aus.
          dir / ls für Suche nach Dateinamen, auch rekursiv
          Oder
          dir / find

          Für Suche nach Datei + nach Inhalt
          https://superuser.com/questions/401495/equivalent-of-unix-find-command-on-windows
          https://man7.org/linux/man-pages/man1/ls.1.html
          https://man7.org/linux/man-pages/man1/find.1.html

          J Codierknecht 2 Replies Last reply Reply Quote 1
          • J
            jacusi @OliverIO last edited by

            @oliverio oh vielen dank dafür

            1 Reply Last reply Reply Quote 0
            • Codierknecht
              Codierknecht Developer Most Active @OliverIO last edited by

              @oliverio sagte in Programmsuchdatei in Java:

              Warum Java?

              Die dunkle Seite der Macht 😁
              Nicht zu verwechseln mit JavaScript.

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

              Support us

              ioBroker
              Community Adapters
              Donate

              820
              Online

              31.8k
              Users

              80.0k
              Topics

              1.3m
              Posts

              4
              5
              312
              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