NbFileUtils { public static void deleteDirectory(final CancellationToken cancelToken, Path directory) throws IOException { Objects.requireNonNull(cancelToken, "cancelToken"); Objects.requireNonNull(directory, "directory"); Files.walkFileTree(directory, new FileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { cancelToken.checkCanceled(); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { cancelToken.checkCanceled(); Files.deleteIfExists(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { cancelToken.checkCanceled(); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { cancelToken.checkCanceled(); Files.deleteIfExists(dir); return FileVisitResult.CONTINUE; } }); } private  NbFileUtils(); static String tryGetLineSeparatorForTextFile(Path file); static String tryMakeRelative(File parent, File file); static String toSafeFileName(String name); static ListenerRef addDirectoryContentListener(
            final FileObject dir,
            final Runnable listener); static ListenerRef addDirectoryContentListener(
            final FileObject dir,
            final boolean listenForDirs,
            final Runnable listener); static URL getSafeURL(String url); static String getFileNameStr(Path path); static FileObject asArchiveOrDir(File file); static FileObject asArchiveOrDir(FileObject file); static FileObject getFileFromASubDir(FileObject root, String fileName); static Path asPath(FileObject fileObj); static Path asPath(File file); static File asFile(FileObject fileObj); static FileObject asFileObject(File file); static boolean isParentOrSame(File parent, File child); static void deleteDirectory(final CancellationToken cancelToken, Path directory); static void deleteDirectory(CancellationToken cancelToken, FileObject directory); static void writeLinesToFile(
            Path file,
            Collection<String> lines,
            Charset charset); static void writeLinesToFile(
            Path file,
            Collection<String> lines,
            Charset charset,
            Project ownerProject); static void writeLinesToFile(
            Path file,
            Collection<String> lines,
            Charset charset,
            String lineSeparator); static Path toSafeRealPath(Path src);  }
@Test public void testDeleteDirectoryAsPath() throws IOException { Path dummyDir = createDummyDirectory(); try { assertTrue(Files.isDirectory(dummyDir)); } finally { NbFileUtils.deleteDirectory(Cancellation.UNCANCELABLE_TOKEN, dummyDir); } assertFalse("Directory must have been removed.", Files.exists(dummyDir)); }
@Test public void testDeleteDirectoryAsFileObject() throws IOException { Path dummyDir = createDummyDirectory(); try { assertTrue(Files.isDirectory(dummyDir)); } finally { FileObject dummyDirAsObj = FileUtil.toFileObject(FileUtil.normalizeFile(dummyDir.toFile())); NbFileUtils.deleteDirectory(Cancellation.UNCANCELABLE_TOKEN, dummyDirAsObj); } assertFalse("Directory must have been removed.", Files.exists(dummyDir)); }