| | |
| | | private Path targetDir; |
| | | private int operation; |
| | | |
| | | /** |
| | | * Den Zielordner fuer Kopier- oder Verschiebeoperationen angeben |
| | | * |
| | | * @param targetDir der Zielordner |
| | | */ |
| | | public void setTargetDir(Path targetDir) { |
| | | this.targetDir = targetDir; |
| | | //logger.fine("targetDir: " + targetDir.toString()); |
| | | } |
| | | |
| | | /** |
| | | * OP_COPY oder OP_MOVE |
| | | * Die gewuenschte Dateioperation angeben, |
| | | * OP_COPY, OP_MOVE oder OP_DELETE |
| | | * |
| | | * @param op |
| | | * @param op die Dateioperation |
| | | */ |
| | | public void setOperation(int op) { |
| | | this.operation = op; |
| | | } |
| | | |
| | | /** |
| | | * Dafuer sorgen, dass beim Kopieren oder Verschieben kein am Ziel bereits existierender |
| | | * Ordner ueberschrieben wird, indem am Ziel fuer einen bereits existierenden Ordner ein |
| | | * anderer Name mit laufender Nummer erzeugt wird. |
| | | * |
| | | * @param dir Zielordner |
| | | * @param attrs die gewuenschten Attribute |
| | | * @return gibt stets FileVisitResult.CONTINUE zurueck |
| | | * @throws IOException wenn etwas schief geht |
| | | */ |
| | | @Override |
| | | public FileVisitResult preVisitDirectory(Object dir, BasicFileAttributes attrs) throws IOException { |
| | | if (operation != Const.OP_DELETE) { |
| | | if (operation != Eraser.OP_DELETE) { |
| | | if (dir instanceof Path) { |
| | | Path sourceDir = (Path) dir; |
| | | File destFile = targetDir.resolve(sourceDir.getFileName()).toFile(); |
| | |
| | | |
| | | @Override |
| | | public FileVisitResult visitFile(Object file, BasicFileAttributes attrs) throws IOException { |
| | | if(operation != Const.OP_DELETE) { |
| | | if(operation != Eraser.OP_DELETE) { |
| | | if (file instanceof Path) { |
| | | Path source = (Path) file; |
| | | File destFile = targetDir.resolve(source.getFileName()).toFile(); |
| | | if (destFile.exists()) { |
| | | destFile = getNewFileName(destFile); |
| | | } |
| | | if (operation == Const.OP_MOVE) { |
| | | if (operation == Mover.OP_MOVE) { |
| | | //logger.fine("move source: " + source.toString() + ", destFile: " + destFile.getAbsolutePath()); |
| | | Files.move(source, destFile.toPath()); |
| | | } else if (operation == Const.OP_COPY) { |
| | | } else if (operation == Mover.OP_COPY) { |
| | | //logger.fine("copy source: " + source.toString() + ", destFile: " + destFile.getAbsolutePath()); |
| | | Files.copy(source, destFile.toPath()); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public FileVisitResult postVisitDirectory(Object dir, IOException exc) throws IOException { |
| | | if (operation != Const.OP_DELETE) { |
| | | if (operation != Eraser.OP_DELETE) { |
| | | if (dir instanceof Path) { |
| | | Path finishedDir = (Path) dir; |
| | | targetDir = targetDir.getParent(); |
| | | if(operation == Const.OP_MOVE) { |
| | | if(operation == Mover.OP_MOVE) { |
| | | //logger.fine("delete " + finishedDir.toString()); |
| | | Files.delete(finishedDir); |
| | | } |