@Test public void movingFileFromExisitingToNotExitsingPath() { OperationsOnFiles.moveWithPruneEmptydirectories(goodSourceFilePath, badTargetFilePath); Assert.assertTrue("File was not moved properly into the target directory.", badTargetfile.exists()); Assert.assertFalse("File still exist in source path after moving.", goodSourceFile.exists()); }
public static void moveWithPruneEmptydirectories(String source, String target) { Path sourcePath; Path targetPath; try { sourcePath = FileSystems.getDefault() .getPath(source); targetPath = FileSystems.getDefault() .getPath(target); createDirectoryIfNotExists(targetPath); Files.move(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING); removeFileAndParentsIfEmpty(sourcePath); } catch (IOException | NullPointerException e) { BFLogger.logError("Unable to move file from: [" + source + "] to: [" + target + "]"); } }
OperationsOnFiles { public static void moveWithPruneEmptydirectories(String source, String target) { Path sourcePath; Path targetPath; try { sourcePath = FileSystems.getDefault() .getPath(source); targetPath = FileSystems.getDefault() .getPath(target); createDirectoryIfNotExists(targetPath); Files.move(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING); removeFileAndParentsIfEmpty(sourcePath); } catch (IOException | NullPointerException e) { BFLogger.logError("Unable to move file from: [" + source + "] to: [" + target + "]"); } } }
OperationsOnFiles { public static void moveWithPruneEmptydirectories(String source, String target) { Path sourcePath; Path targetPath; try { sourcePath = FileSystems.getDefault() .getPath(source); targetPath = FileSystems.getDefault() .getPath(target); createDirectoryIfNotExists(targetPath); Files.move(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING); removeFileAndParentsIfEmpty(sourcePath); } catch (IOException | NullPointerException e) { BFLogger.logError("Unable to move file from: [" + source + "] to: [" + target + "]"); } } private  OperationsOnFiles(); }
OperationsOnFiles { public static void moveWithPruneEmptydirectories(String source, String target) { Path sourcePath; Path targetPath; try { sourcePath = FileSystems.getDefault() .getPath(source); targetPath = FileSystems.getDefault() .getPath(target); createDirectoryIfNotExists(targetPath); Files.move(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING); removeFileAndParentsIfEmpty(sourcePath); } catch (IOException | NullPointerException e) { BFLogger.logError("Unable to move file from: [" + source + "] to: [" + target + "]"); } } private  OperationsOnFiles(); static void moveWithPruneEmptydirectories(String source, String target); static void removeFileAndParentsIfEmpty(Path path); }
OperationsOnFiles { public static void moveWithPruneEmptydirectories(String source, String target) { Path sourcePath; Path targetPath; try { sourcePath = FileSystems.getDefault() .getPath(source); targetPath = FileSystems.getDefault() .getPath(target); createDirectoryIfNotExists(targetPath); Files.move(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING); removeFileAndParentsIfEmpty(sourcePath); } catch (IOException | NullPointerException e) { BFLogger.logError("Unable to move file from: [" + source + "] to: [" + target + "]"); } } private  OperationsOnFiles(); static void moveWithPruneEmptydirectories(String source, String target); static void removeFileAndParentsIfEmpty(Path path);  }