fork download
  1. public static void moveUpOneFolder(Path parent) {
  2.  
  3. try (DirectoryStream<Path> ds1 = Files.newDirectoryStream(parent)) {
  4. for (Path p1 : ds1) {
  5. //if this node is a dir, traverse its content
  6. if (Files.isDirectory(p1)) {
  7. moveUpOneFolder(p1);
  8. }
  9. Files.delete(p1);
  10. }
  11. } catch (IOException e) {
  12. e.printStackTrace();
  13. }
  14. try (DirectoryStream<Path> ds1 = Files.newDirectoryStream(parent)) {
  15. for (Path p1 : ds1) {
  16. //this node must be a file. move it up one level
  17. Path newFileName = parent.getParent().resolve(p1.getName(p1.getNameCount() - 2) + "_" + p1.getFileName());
  18. Files.move(p1, newFileName);
  19. Files.delete(p1);
  20. }
  21.  
  22. } catch (IOException e) {
  23. e.printStackTrace();
  24. }
  25. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty