|  |  |  | 
|---|
|  |  |  | import java.nio.file.Path; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * Die Klasse Mover verschiebt und kopiert Dateien und Ordner | 
|---|
|  |  |  | * Verschieben und Kopieren von Dateien und Ordnern | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * Handhabung von Bilddateien: | 
|---|
|  |  |  | * | 
|---|
|  |  |  | 
|---|
|  |  |  | public static final int OP_MOVE = 2; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * Dateien und Ordner kopieren | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param fromPath der Pfad zur Quelle  der Kopieraktion | 
|---|
|  |  |  | * @param toPath der Pfad zum Ziel der Kopieraktion | 
|---|
|  |  |  | * @param fileNames die Liste der Dateien und Ordner, die kopiert werden sollen | 
|---|
|  |  |  | * @param base der Basispfad, gegen den fromPath und toPath aufgeloest werden sollen | 
|---|
|  |  |  | * @throws IOException wenn etwas schief geht | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void copy(String fromPath, String toPath, String[] fileNames, String base) | 
|---|
|  |  |  | throws IOException { | 
|---|
|  |  |  | copyOrMoveFiles(fromPath, toPath, fileNames, OP_COPY, base); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * Dateien und Ordner verschieben | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param fromPath der Pfad zur Quelle  der Verschiebeaktion | 
|---|
|  |  |  | * @param toPath der Pfad zum Ziel der Verschiebeaktion | 
|---|
|  |  |  | * @param fileNames die Liste der Dateien und Ordner, die verschoben werden sollen | 
|---|
|  |  |  | * @param base der Basispfad, gegen den fromPath und toPath aufgeloest werden sollen | 
|---|
|  |  |  | * @throws IOException wenn etwas schief geht | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void move(String fromPath, String toPath, String[] fileNames, String base) | 
|---|
|  |  |  | throws IOException { | 
|---|
|  |  |  | copyOrMoveFiles(fromPath, toPath, fileNames, OP_MOVE, base); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * Dateien und Ordner verschieben oder kopieren | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param fromPath der Pfad zur Quelle  der Verschiebe- oder Kopieraktion | 
|---|
|  |  |  | 
|---|
|  |  |  | * @param base der Basispfad, gegen den fromPath und toPath aufgeloest werden sollen | 
|---|
|  |  |  | * @throws IOException wenn etwas schief geht | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void copyOrMoveFiles(String fromPath, String toPath, String[] fileNames, | 
|---|
|  |  |  | private void copyOrMoveFiles(String fromPath, String toPath, String[] fileNames, | 
|---|
|  |  |  | int operation, String base) throws IOException { | 
|---|
|  |  |  | //String result = null; | 
|---|
|  |  |  | File srcDir = new File(base, fromPath); | 
|---|
|  |  |  | 
|---|
|  |  |  | //logger.fine("srcFile: " + srcFile); | 
|---|
|  |  |  | if (srcFile.isDirectory()) { | 
|---|
|  |  |  | //logger.fine("srcFile is directory."); | 
|---|
|  |  |  | CopyMoveVisitor bearbeiter = new CopyMoveVisitor(); | 
|---|
|  |  |  | FileOpsVisitor bearbeiter = new FileOpsVisitor(); | 
|---|
|  |  |  | bearbeiter.setTargetDir(targetDir.toPath()); | 
|---|
|  |  |  | bearbeiter.setOperation(operation); | 
|---|
|  |  |  | Files.walkFileTree(srcFile.toPath(), bearbeiter); | 
|---|