@Test public void moveFolderToNewFolder() throws IOException { Path parentdir = Files.createTempDirectory("DIR"); Path parentdirMove = Files.createDirectory(PathUtils.get(parentdir, "DIR_MOVE/")); FileUtils.move(parentdirMove, PathUtils.get(parentdir, "DIR2")); assertThat(exists(parentdirMove), is(false)); assertThat(exists(PathUtils.get(parentdir, "DIR2")), is(true)); }
public static void move(Path from, Path to) { try { if(Files.isDirectory(from)) { Files.walkFileTree(from, new MoveVistor(from, to)); } else if (Files.isRegularFile(from)) { if (Files.notExists(to)){ Path parent = to.getParent(); createDirectories(parent); } else if(Files.isDirectory(to)) { to = to.resolve(from.getFileName()); } else if(Files.isRegularFile(to)){ } Files.move(from, to, ATOMIC_MOVE, REPLACE_EXISTING); } } catch (IOException e) { throw new RuntimeException(e); } }
FileUtils { public static void move(Path from, Path to) { try { if(Files.isDirectory(from)) { Files.walkFileTree(from, new MoveVistor(from, to)); } else if (Files.isRegularFile(from)) { if (Files.notExists(to)){ Path parent = to.getParent(); createDirectories(parent); } else if(Files.isDirectory(to)) { to = to.resolve(from.getFileName()); } else if(Files.isRegularFile(to)){ } Files.move(from, to, ATOMIC_MOVE, REPLACE_EXISTING); } } catch (IOException e) { throw new RuntimeException(e); } } }
FileUtils { public static void move(Path from, Path to) { try { if(Files.isDirectory(from)) { Files.walkFileTree(from, new MoveVistor(from, to)); } else if (Files.isRegularFile(from)) { if (Files.notExists(to)){ Path parent = to.getParent(); createDirectories(parent); } else if(Files.isDirectory(to)) { to = to.resolve(from.getFileName()); } else if(Files.isRegularFile(to)){ } Files.move(from, to, ATOMIC_MOVE, REPLACE_EXISTING); } } catch (IOException e) { throw new RuntimeException(e); } } private  FileUtils(); }
FileUtils { public static void move(Path from, Path to) { try { if(Files.isDirectory(from)) { Files.walkFileTree(from, new MoveVistor(from, to)); } else if (Files.isRegularFile(from)) { if (Files.notExists(to)){ Path parent = to.getParent(); createDirectories(parent); } else if(Files.isDirectory(to)) { to = to.resolve(from.getFileName()); } else if(Files.isRegularFile(to)){ } Files.move(from, to, ATOMIC_MOVE, REPLACE_EXISTING); } } catch (IOException e) { throw new RuntimeException(e); } } private  FileUtils(); static void delete(Path path); static void delete(Path path, String glob); static void deleteDir(Path dir, DeleteVisitor visitor); static void copy(Path source, Path target); static void copy(Path source, Path target, String glob); static void copy(CopyVisitor visitor); static void copyFile(Path source, Path target); static Path createFile(Path dir, String name); static Path createDirectories(Path dir); static String read(Path file); static String read(Path file, Charset charset); static List<Path> ls(Path dir); static void move(Path from, Path to); static void createSymbolicLink(Path link, Path targetFile); }
FileUtils { public static void move(Path from, Path to) { try { if(Files.isDirectory(from)) { Files.walkFileTree(from, new MoveVistor(from, to)); } else if (Files.isRegularFile(from)) { if (Files.notExists(to)){ Path parent = to.getParent(); createDirectories(parent); } else if(Files.isDirectory(to)) { to = to.resolve(from.getFileName()); } else if(Files.isRegularFile(to)){ } Files.move(from, to, ATOMIC_MOVE, REPLACE_EXISTING); } } catch (IOException e) { throw new RuntimeException(e); } } private  FileUtils(); static void delete(Path path); static void delete(Path path, String glob); static void deleteDir(Path dir, DeleteVisitor visitor); static void copy(Path source, Path target); static void copy(Path source, Path target, String glob); static void copy(CopyVisitor visitor); static void copyFile(Path source, Path target); static Path createFile(Path dir, String name); static Path createDirectories(Path dir); static String read(Path file); static String read(Path file, Charset charset); static List<Path> ls(Path dir); static void move(Path from, Path to); static void createSymbolicLink(Path link, Path targetFile);  }