UnixPath { public boolean deleteRecursively() { if (!isSymbolicLink() && isDirectory()) { try (Stream<UnixPath> paths = listContentsOfDirectory()) { paths.forEach(UnixPath::deleteRecursively); } } return uncheck(() -> Files.deleteIfExists(path)); } UnixPath(Path path);  UnixPath(String path); Path toPath(); UnixPath resolve(String relativeOrAbsolutePath); UnixPath getParent(); String getFilename(); boolean exists(); String readUtf8File(); Optional<String> readUtf8FileIfExists(); byte[] readBytes(); Optional<byte[]> readBytesIfExists(); UnixPath writeUtf8File(String content, OpenOption... options); UnixPath writeBytes(byte[] content, OpenOption... options); UnixPath atomicWriteUt8(String content); UnixPath atomicWriteBytes(byte[] content); String getPermissions(); UnixPath setPermissions(String permissions); String getOwner(); UnixPath setOwner(String owner); String getGroup(); UnixPath setGroup(String group); Instant getLastModifiedTime(); UnixPath updateLastModifiedTime(); UnixPath setLastModifiedTime(Instant instant); FileAttributes getAttributes(); Optional<FileAttributes> getAttributesIfExists(); UnixPath createNewFile(); UnixPath createNewFile(String permissions); UnixPath createParents(); UnixPath createDirectory(String permissions); UnixPath createDirectory(); boolean isDirectory(); boolean isSymbolicLink(); boolean deleteRecursively(); UnixPath deleteIfExists(); Stream<UnixPath> listContentsOfDirectory(); UnixPath atomicMove(Path to); boolean moveIfExists(Path to); UnixPath createSymbolicLink(Path link); FileSnapshot getFileSnapshot(); @Override String toString();  }
@Test public void deleteRecursively() throws Exception { var dir1 = fs.getPath("/dir1"); var dir2 = dir1.resolve("dir2"); var file1 = dir2.resolve("file1"); Files.createDirectories(dir2); Files.writeString(file1, "file1"); var link1 = Files.createSymbolicLink(fs.getPath("/link1"), dir2); new UnixPath(link1).deleteRecursively(); assertTrue("Deleting " + link1 + " recursively does not remove " + dir2, Files.exists(dir2)); assertTrue("Deleting " + link1 + " recursively does not remove " + file1, Files.exists(file1)); new UnixPath(dir1).deleteRecursively(); assertFalse(dir1 + " deleted recursively", Files.exists(file1)); assertFalse(dir1 + " deleted recursively", Files.exists(dir2)); assertFalse(dir1 + " deleted recursively", Files.exists(dir1)); }