| | |
| | | */ |
| | | private void copyOrMoveFiles(String fromPath, String toPath, String[] fileNames, |
| | | int operation, String base) throws IOException { |
| | | //String result = null; |
| | | File srcDir = new File(base, fromPath); |
| | | File targetDir = new File(base, toPath); |
| | | for (String fileName : fileNames) { |
| | | File srcFile = new File(srcDir, fileName); |
| | | //logger.fine("srcFile: " + srcFile); |
| | | if (srcFile.isDirectory()) { |
| | | //logger.fine("srcFile is directory."); |
| | | FileOpsVisitor bearbeiter = new FileOpsVisitor(); |
| | | bearbeiter.setTargetDir(targetDir.toPath()); |
| | | bearbeiter.setOperation(operation); |
| | |
| | | if (destFile.exists()) { |
| | | destFile = getNewFileName(destFile); |
| | | } |
| | | if (operation == OP_MOVE) { |
| | | String fname = srcFile.getName().toLowerCase(); |
| | | if (fname.endsWith(ImageFileFilter.JPEG) |
| | | || fname.endsWith(ImageFileFilter.JPG) |
| | | || fname.endsWith(ImageFileFilter.PNG)) { |
| | | moveImgFilesToDirectory(srcFile, srcDir, targetDir/*, false*/); |
| | | } else { |
| | | Files.move(source, destFile.toPath()); |
| | | } |
| | | String fname = srcFile.getName().toLowerCase(); |
| | | if (fname.endsWith(ImageFileFilter.JPEG) |
| | | || fname.endsWith(ImageFileFilter.JPG) |
| | | || fname.endsWith(ImageFileFilter.PNG)) { |
| | | copyOrMoveImgFilesToDirectory(srcFile, srcDir, targetDir/*, false*/, operation); |
| | | } else { |
| | | Files.copy(source, destFile.toPath()); |
| | | } |
| | | if (operation == OP_MOVE) { |
| | | Files.move(source, destFile.toPath()); |
| | | } else { |
| | | Files.copy(source, destFile.toPath()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //return result; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param targetDir der Zielort |
| | | * @throws IOException wenn etwas schief geht |
| | | */ |
| | | private void moveImgFilesToDirectory(File srcFile, File srcDir, File targetDir/*, |
| | | boolean createDestDir*/) throws IOException { |
| | | private void copyOrMoveImgFilesToDirectory(File srcFile, File srcDir, File targetDir, |
| | | int operation) throws IOException { |
| | | String fnameext = srcFile.getName(); |
| | | int dotpos = fnameext.lastIndexOf("."); |
| | | String fname = fnameext.substring(0, dotpos); |
| | | String ext = fnameext.substring(dotpos); |
| | | //logger.fine("fname: " + fname + ", ext: " + ext); |
| | | Path targetPath = targetDir.toPath(); |
| | | DirectoryStream<Path> stream = Files.newDirectoryStream(srcDir.toPath(), fname + "*" + ext); |
| | | //"*.{txt,doc,pdf,ppt}" |
| | | for (Path path : stream) { |
| | | //logger.fine(path.getFileName().toString()); |
| | | //Files.delete(path); |
| | | Files.move(path, targetPath.resolve(path.getFileName())); |
| | | if(operation == OP_COPY) { |
| | | Files.copy(path, targetPath.resolve(path.getFileName())); |
| | | } else { |
| | | Files.move(path, targetPath.resolve(path.getFileName())); |
| | | } |
| | | } |
| | | stream.close(); |
| | | } |