public static boolean rmdir(Path dir) {
        if (!Files.exists(dir)) {
            return false;
        }

        if (!Files.isDirectory(dir)) {
            throw new IllegalArgumentException(dir + " is not a directory");
        }

        try {
            Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
                @Override
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                    // Workaround for Windows systems that set some git packfiles to readonly
                    file.toFile().setWritable(true);

                    Files.delete(file);
                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
                    return Files.isSymbolicLink(dir)
                            // Don't delete symlink files, just delete the symlink.
                            ? FileVisitResult.SKIP_SUBTREE
                            : FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
                    if (e != null) {
                        throw e;
                    }
                    Files.delete(dir);
                    return FileVisitResult.CONTINUE;
                }
            });
        } catch (IOException e) {
            throw new RuntimeException("Error deleting directory: " + dir + ": " + e.getMessage(), e);
        }

        return true;
    }
Delete a directory and all files within.

<p>Any found symlink is deleted, but the contents of a symlink are not deleted.

@param dir Directory to delete.
@return Returns true if the directory was deleted, or false if the directory does not exist.
@throws IllegalArgumentException if the given path is not a directory.
@throws RuntimeException if unable to delete a file or directory.
smithy-utils/src/main/java/software/amazon/smithy/utils/IoUtils.java