Beispiel #1
0
  private static List<String> doListByFileExtensionRecursive(
      final List<String> result, final Path pathFromFileSystem, final String glob) {

    try {
      try (DirectoryStream<Path> stream = Files.newDirectoryStream(pathFromFileSystem, glob)) {
        for (Path entry : stream) {
          result.add(entry.toAbsolutePath().toString());
        }
      }
      try (DirectoryStream<Path> stream = Files.newDirectoryStream(pathFromFileSystem)) {
        for (Path entry : stream) {
          if (Files.isDirectory(entry)) {
            doListByFileExtensionRecursive(result, entry, glob);
          }
        }
      }

      return result;
    } catch (IOException ex) {
      return Exceptions.handle(List.class, ex);
    }
  }
Beispiel #2
0
  public static List<String> listByGlob(Path pathFromFileSystem, String glob) {

    List<String> result = new ArrayList<>();

    try {
      try (DirectoryStream<Path> stream = Files.newDirectoryStream(pathFromFileSystem, glob)) {
        for (Path entry : stream) {
          result.add(entry.toAbsolutePath().toString());
        }
      }
      return result;
    } catch (IOException ex) {
      return Exceptions.handle(List.class, ex);
    }
  }
Beispiel #3
0
  public static List<String> list(final Path path) {

    List<String> result = new ArrayList<>();

    try {
      try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(path)) {
        for (Path entry : directoryStream) {
          result.add(entry.toAbsolutePath().toString());
        }
      }
      return result;
    } catch (IOException ex) {
      return Exceptions.handle(List.class, ex);
    }
  }
Beispiel #4
0
  public static List<String> listByFileExtension(final Path pathFromFileSystem, final String ext) {
    final String extToLookForGlob = "*." + ext;

    List<String> result = new ArrayList<>();

    try {
      try (DirectoryStream<Path> stream =
          Files.newDirectoryStream(pathFromFileSystem, extToLookForGlob)) {
        for (Path entry : stream) {
          result.add(entry.toAbsolutePath().toString());
        }
      }
      return result;
    } catch (IOException ex) {
      return Exceptions.handle(List.class, ex);
    }
  }
Beispiel #5
0
    private int getNumberOfItems(Path quellOrdner) {
      int retValue = 0;

      try {
        DirectoryStream<Path> qstream = Files.newDirectoryStream(quellOrdner);
        for (Path qfile : qstream) {
          if (Files.isDirectory(qfile)) {
            getNumberOfItems(Paths.get(quellOrdner.toString() + "/" + qfile.getFileName()));
          }
          i++;
        }
        qstream.close();
      } catch (IOException e) {
        e.printStackTrace();
      }

      retValue = i;
      return retValue;
    }
Beispiel #6
0
    public void cnpStart(Path quellOrdner, Path zielOrdner) {
      try {
        DirectoryStream<Path> qstream = Files.newDirectoryStream(quellOrdner);
        for (Path qfile : qstream) {
          Path target = Paths.get(zielOrdner.toString() + "/" + qfile.getFileName());
          if (abbruch) break;
          if (Files.isDirectory(qfile) && !Files.exists(target)) {
            Files.createDirectory(target);
            textArea.append("Verzeichnis: " + qfile + " wurde erstellt" + System.lineSeparator());
            cnpStart(
                Paths.get(quellOrdner.toString() + "/" + qfile.getFileName()),
                Paths.get(zielOrdner.toString() + "/" + qfile.getFileName()));
          } else if (Files.isDirectory(qfile) && Files.exists(target)) {
            textArea.append("Wechsle in Verzeichnis: " + qfile + System.lineSeparator());
            cnpStart(
                Paths.get(quellOrdner.toString() + "/" + qfile.getFileName()),
                Paths.get(zielOrdner.toString() + "/" + qfile.getFileName()));
          }
          // Wenn die Datei noch nicht existiert
          else if (!Files.exists(target)) {
            textArea.append(
                "Datei " + target.toString() + " wurde erstellt" + System.lineSeparator());
            Files.copy(qfile, target, StandardCopyOption.REPLACE_EXISTING);

          }
          // Wenn Datei im Zielverzeichnis schon existiert
          else if (Files.exists(target)) {
            if (cAUeSchr) {
              textArea.append(
                  "Datei "
                      + target.toString()
                      + " wird absolut überschrieben"
                      + System.lineSeparator());
              Files.copy(qfile, target, StandardCopyOption.REPLACE_EXISTING);
            } else if (cUeSchr) {
              if (checkAlter(
                  Paths.get(quellOrdner.toString() + "/" + qfile.getFileName()),
                  Paths.get(zielOrdner.toString() + "/" + qfile.getFileName()))) {
                textArea.append(
                    target.toString()
                        + " wird mit neuer Datei überschrieben"
                        + System.lineSeparator());
                Files.copy(qfile, target, StandardCopyOption.REPLACE_EXISTING);
              } else {
                textArea.append(
                    target.toString() + " alte Datei bleibt bestehen" + System.lineSeparator());
              }
            } else
              textArea.append(
                  target.toString() + " alte Datei bleibt bestehen" + System.lineSeparator());
          }
          pbCounter++;
          progressBar.setValue(pbCounter);
        }

        qstream.close();
      } catch (IOException e) {

        e.printStackTrace();
      }
    }