| | |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Path; |
| | | import java.nio.file.attribute.BasicFileAttributes; |
| | | import java.util.logging.Logger; |
| | | |
| | | /** |
| | | * Ein FileVisitor zum Verschieben oder Kopieren ganzer Ordnerstrukturen mit |
| | |
| | | */ |
| | | public class OrdnerBearbeiter extends FileTransporter implements FileVisitor { |
| | | |
| | | /* Der Logger fuer diesen ListFileHandler */ |
| | | private static final Logger logger = Logger.getLogger(OrdnerBearbeiter.class.getName()); |
| | | |
| | | private Path targetDir; |
| | | private int operation; |
| | | |
| | | public void setTargetDir(Path targetDir) { |
| | | this.targetDir = targetDir; |
| | | logger.fine("targetDir: " + targetDir.toString()); |
| | | //logger.fine("targetDir: " + targetDir.toString()); |
| | | } |
| | | |
| | | /** |
| | |
| | | if (dir instanceof Path) { |
| | | Path sourceDir = (Path) dir; |
| | | File destFile = targetDir.resolve(sourceDir.getFileName()).toFile(); |
| | | logger.fine("sourceDir: " + sourceDir + ", destFile: " + destFile); |
| | | //logger.fine("sourceDir: " + sourceDir + ", destFile: " + destFile); |
| | | if (destFile.exists()) { |
| | | File newDir = getNewFileName(destFile); |
| | | destFile.renameTo(newDir); |
| | | } |
| | | destFile.mkdir(); |
| | | this.targetDir = destFile.toPath(); |
| | | logger.fine("targetDir now: " + targetDir.toString()); |
| | | //logger.fine("targetDir now: " + targetDir.toString()); |
| | | } |
| | | } |
| | | return FileVisitResult.CONTINUE; |
| | |
| | | destFile = getNewFileName(destFile); |
| | | } |
| | | if (operation == FileManager.OP_MOVE) { |
| | | logger.fine("move source: " + source.toString() + ", destFile: " + destFile.getAbsolutePath()); |
| | | //logger.fine("move source: " + source.toString() + ", destFile: " + destFile.getAbsolutePath()); |
| | | Files.move(source, destFile.toPath()); |
| | | } else if (operation == FileManager.OP_COPY) { |
| | | logger.fine("copy source: " + source.toString() + ", destFile: " + destFile.getAbsolutePath()); |
| | | //logger.fine("copy source: " + source.toString() + ", destFile: " + destFile.getAbsolutePath()); |
| | | Files.copy(source, destFile.toPath()); |
| | | } |
| | | } |
| | |
| | | Path finishedDir = (Path) dir; |
| | | targetDir = targetDir.getParent(); |
| | | if(operation == FileManager.OP_MOVE) { |
| | | logger.fine("delete " + finishedDir.toString()); |
| | | //logger.fine("delete " + finishedDir.toString()); |
| | | Files.delete(finishedDir); |
| | | } |
| | | } |
| | | logger.fine("targetDir now: " + targetDir.toString()); |
| | | //logger.fine("targetDir now: " + targetDir.toString()); |
| | | } else { |
| | | Files.delete((Path) dir); |
| | | } |