From c6b6d94fe81f669e229612ed2e336625650ebe6e Mon Sep 17 00:00:00 2001 From: ulrich Date: Fri, 15 Nov 2024 10:01:48 +0000 Subject: [PATCH] Build-Anweisungen ergaenzt --- src/de/uhilger/fm/Mover.java | 40 ++++++++++++++++++---------------------- 1 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/de/uhilger/fm/Mover.java b/src/de/uhilger/fm/Mover.java index e92aac7..5b452db 100644 --- a/src/de/uhilger/fm/Mover.java +++ b/src/de/uhilger/fm/Mover.java @@ -79,14 +79,11 @@ */ 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); @@ -97,21 +94,20 @@ 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; } /** @@ -126,20 +122,20 @@ * @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(); } -- Gitblit v1.9.3