Java 类java.nio.file.FileVisitResult 实例源码

项目:Squid    文件:FileUtilities.java   
/**
 *
 * @param directory
 * @throws IOException
 */
public static void recursiveDelete(Path directory) throws IOException {
    Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(
                Path file,
                BasicFileAttributes attrs) throws IOException {

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

        @Override
        public FileVisitResult postVisitDirectory(
                Path dir,
                IOException exc) throws IOException {

            Files.delete(dir);
            return FileVisitResult.CONTINUE;
        }
    });
}
项目:Hollow-Knight-SaveManager    文件:Listeners.java   
public static void deleteFiles (String path){    
     try {
         Path directory = Paths.get(path);
         Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                Files.delete(file);
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                Files.delete(dir);
                return FileVisitResult.CONTINUE;
            }
         });
    } catch (IOException e) {
        e.printStackTrace();
    }      
}
项目:launcher-backend    文件:FileUploadHelper.java   
/**
 * Deletes a directory recursively
 *
 * @param directory
 * @return true if deletion succeeds, false otherwise
 */
public static boolean deleteDirectory(Path directory) {
    if (directory != null) {
        try {
            Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
                @Override
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                    Files.delete(file);
                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                    Files.delete(dir);
                    return FileVisitResult.CONTINUE;
                }
            });
        } catch (IOException ignored) {
            return false;
        }
    }
    return true;
}
项目:openjdk-jdk10    文件:ClasspathDependencies.java   
static void delete(Path root) throws IOException {
    if (!Files.exists(root))
        return;
    Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
             @Override
             public FileVisitResult visitFile(Path f, BasicFileAttributes a)
                     throws IOException {
                 Files.delete(f);
                 return FileVisitResult.CONTINUE;
             }

             @Override
             public FileVisitResult postVisitDirectory(Path dir, IOException e)
                     throws IOException {
                 if (e != null)
                     throw e;
                 if (!dir.equals(root))
                     Files.delete(dir);
                 return FileVisitResult.CONTINUE;
             }
        });
}
项目:Lagerta    文件:FileUtils.java   
/**
 * Deletes directory along with all inner files.
 *
 * @param path to directory.
 * @throws IOException if there are errors during deleting.
 */
public static void deleteDir(Path path) throws IOException {
    if (!Files.exists(path)) {
        return;
    }
    Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
        @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            Files.delete(file);
            return FileVisitResult.CONTINUE;
        }

        @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
            Files.delete(dir);
            return super.postVisitDirectory(dir, exc);
        }
    });
}
项目:sumo    文件:ClearCacheAction.java   
@Override
public boolean execute() {
    File folder=CacheManager.getRootCacheInstance().getPath();
    //System.gc();
    try {
        Files.walkFileTree(folder.toPath(), new SimpleFileVisitor<Path>() {
               @Override
               public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                   Files.delete(file);
                   return FileVisitResult.CONTINUE;
               }

               @Override
               public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                   Files.delete(dir);
                   return FileVisitResult.CONTINUE;
               }

           });
    } catch (IOException e) {
        logger.error(e.getMessage());
        return false;
    }
    super.notifyEvent(new SumoActionEvent(SumoActionEvent.ENDACTION,"cache cleaned...", -1));
    return true;
}
项目:jpa2ddl    文件:FileResolver.java   
static List<String> listClassNamesInPackage(String packageName) throws Exception {
    List<String> classes = new ArrayList<>();
    Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources(packageName.replace('.', File.separatorChar));
    if (!resources.hasMoreElements()) {
        throw new IllegalStateException("No package found: " + packageName);
    }
    PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:*.class");
    while (resources.hasMoreElements()) {
        URL resource = resources.nextElement();
        Files.walkFileTree(Paths.get(resource.toURI()), new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
                if (pathMatcher.matches(path.getFileName())) {
                    try {
                        String className = Paths.get(resource.toURI()).relativize(path).toString().replace(File.separatorChar, '.');
                        classes.add(packageName + '.' + className.substring(0, className.length() - 6));
                    } catch (URISyntaxException e) {
                        throw new IllegalStateException(e);
                    }
                }
                return FileVisitResult.CONTINUE;
            }
        });
    }
    return classes;
}
项目:bazel-tools    文件:PathUtils.java   
public static void removeRecursive(final Path path) throws IOException {
  Files.walkFileTree(
      path,
      new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs)
            throws IOException {
          Files.deleteIfExists(file);
          return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult postVisitDirectory(final Path dir, final IOException exc)
            throws IOException {
          Files.deleteIfExists(dir);
          return FileVisitResult.CONTINUE;
        }
      });
}
项目:chipKIT-importer    文件:ChipKitProjectImporter.java   
private void importSketchFiles( Path sketchDirPath ) throws IOException {
    if ( !copyingFiles ) return;
    Files.walkFileTree(sketchDirPath, new CopyingFileVisitor(sketchDirPath, getSourceFilesDirectoryPath(), PROJECT_SOURCE_FILE_MATCHER) {
        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
            if ( file.toString().endsWith(".ino.cpp") ) {
                String filename = file.getFileName().toString();
                String newFilename = filename.replace(".ino.cpp", ".cpp");
                Path targetFilePath = target.resolve( source.relativize( Paths.get(file.getParent().toString(), newFilename) ) );
                copyFile( file, targetFilePath );
                try {
                    removeLineDirectives( targetFilePath);
                } catch (IOException ex) {
                    throw new UncheckedIOException(ex);
                }
            } else { 
                copyFile( file, target.resolve( source.relativize(file) ) );
            }
            return CONTINUE;
        }            
    });
}
项目:VKMusicUploader    文件:WatchDirs.java   
/**
 * Starts watching the subdirectories of the provided directory for changes.
 * @param root Root directory of the subdirectories to register.
 * @throws IOException If a subdirectory cannot be registered.
 * @checkstyle RequireThisCheck (20 lines)
 * @checkstyle NonStaticMethodCheck (20 lines)
 */
private void processSubevents(final Path root) throws IOException {
    try {
        Files.walkFileTree(
            root,
            new SimpleFileVisitor<Path>() {
                @Override
                public FileVisitResult preVisitDirectory(
                    final Path subdir,
                    final BasicFileAttributes attrs
                ) throws IOException {
                    registerDirectory(subdir);
                    return FileVisitResult.CONTINUE;
                }
            });
    } catch (final IOException ex) {
        throw new IOException("Failed to register subdirectories", ex);
    }
}
项目:java-course    文件:LsShellCommand.java   
@Override
public FileVisitResult preVisitDirectory(Path dir,
        BasicFileAttributes attrs) throws IOException {
    String dirName = dir.toFile().getName();
    long directorySize = getDirectorySize(dir.toFile());

    printAttributes(getPermissions(dir), directorySize,
            getFormattedDate(dir), dirName);
    return FileVisitResult.CONTINUE;
}
项目:Equella    文件:FileUtils.java   
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException
{
    if( exc != null )
    {
        success = false;
        LOGGER.warn("Folder traversal failed.  Could not traverse " + dir.toString());
    }
    try
    {
        Files.delete(dir);
    }
    catch( Exception e )
    {
        success = false;
        LOGGER.warn("Folder deletion failed.  Could not delete " + dir.toString());
    }
    return FileVisitResult.CONTINUE;
}
项目:jtsgen    文件:TsGenProcessorTmpDirTest.java   
@After
public void deleteTmpDir() throws IOException {
    Files.walkFileTree(this.tmpDir, new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult postVisitDirectory(final Path theDir, final IOException e) throws IOException {
            if (e != null) return TERMINATE;
            Files.delete(theDir);
            return CONTINUE;
        }

        @Override
        public FileVisitResult visitFile(final Path theFile, final BasicFileAttributes attrs) throws IOException {
            Files.delete(theFile);
            return CONTINUE;
        }
    });
}
项目:cljbuck    文件:PathTraversal.java   
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
    final String d = dir.getFileName().toString();
    final String abs = dir.toAbsolutePath().toString();

    if (d.startsWith(".")) {
        return SKIP_SUBTREE;
    } else if (abs.equals(workspacePath+"/clj-out")) {
        return SKIP_SUBTREE;
    } else if (abs.equals(workspacePath+"/target")) {
        return SKIP_SUBTREE;
    } else if (abs.equals(workspacePath+"/buck-out")) {
        return SKIP_SUBTREE;
    }
    find(dir);
    return CONTINUE;
}
项目:guava-mock    文件:MoreFilesTest.java   
@Override
protected void tearDown() throws Exception {
  if (tempDir != null) {
    // delete tempDir and its contents
    Files.walkFileTree(tempDir, new SimpleFileVisitor<Path>() {
      @Override
      public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
        Files.deleteIfExists(file);
        return FileVisitResult.CONTINUE;
      }

      @Override
      public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
        if (exc != null) {
          return FileVisitResult.TERMINATE;
        }
        Files.deleteIfExists(dir);
        return FileVisitResult.CONTINUE;
      }
    });
  }
}
项目:ProjectAres    文件:MapSource.java   
public Set<Path> getMapFolders(final Logger logger) throws IOException {
    final Set<Path> mapFolders = new HashSet<>();
    for(Path root : getRootPaths()) {
        int depth = "".equals(root.toString()) ? 0 : Iterables.size(root);
        Files.walkFileTree(getPath().resolve(root), ImmutableSet.of(FileVisitOption.FOLLOW_LINKS), maxDepth - depth, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
                if(!isExcluded(dir)) {
                    if(MapFolder.isMapFolder(dir)) {
                        mapFolders.add(dir);
                    }
                    return FileVisitResult.CONTINUE;
                } else {
                    logger.fine("Skipping excluded path " + dir);
                    return FileVisitResult.SKIP_SUBTREE;
                }
            }
        });
    }
    return mapFolders;
}
项目:omero-ms-queue    文件:ClassPathFactory.java   
/**
 * Builds a class path with all the files selected by the given predicate 
 * in the specified base directory and, recursively, in all of its 
 * sub-directories.
 * @param dir the directory in which to find the (jar) files.
 * @param select tests whether or not to include a regular file.
 * @return the class path.
 * @throws NullPointerException if the argument is {@code null}.
 * @throws IOException if an I/O error occurs while trawling the directory.
 */
public static ClassPath fromDir(Path dir, Predicate<Path> select) 
        throws IOException {
    requireNonNull(dir, "dir");
    requireNonNull(select, "select");

    ClassPath cp = new ClassPath();

    Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(Path file,
                BasicFileAttributes attrs) throws IOException {
            if (attrs.isRegularFile() && select.test(file)) {
                cp.add(file);
            }
            return FileVisitResult.CONTINUE;
        }
    });

    return cp;
}
项目:Lagerta    文件:FileUtils.java   
/**
 * Deletes directory along with all inner files.
 *
 * @param path to directory.
 * @throws IOException if there are errors during deleting.
 */
public static void deleteDir(Path path) throws IOException {
    if (!Files.exists(path)) {
        return;
    }
    Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
        @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            Files.delete(file);
            return FileVisitResult.CONTINUE;
        }

        @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
            Files.delete(dir);
            return super.postVisitDirectory(dir, exc);
        }
    });
}
项目:sstable-adaptor    文件:DirectorySizeCalculator.java   
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
{
    if (isAcceptable(file))
        size += attrs.size();
    return FileVisitResult.CONTINUE;
}
项目:openjdk-jdk10    文件:Basic.java   
@Override
public FileVisitResult visitFile(Path file,
                                 BasicFileAttributes attrs)
{
    indent();
    System.out.print(file.getFileName());
    if (attrs.isRegularFile())
        System.out.format("%n%s%n", attrs);

    System.out.println();
    return FileVisitResult.CONTINUE;
}
项目:Java_Swing_Programming    文件:FWI.java   
@Override
public FileVisitResult visitFile(Object file, BasicFileAttributes attrs) throws IOException {
   Path p= (Path)file; //To change body of generated methods, choose Tools | Templates.

   PathMatcher pm= FileSystems.getDefault().getPathMatcher("glob:**.{log}");
   if(pm.matches(p)){
        System.out.println(p.toString());
   }
   return FileVisitResult.CONTINUE;
}
项目:n4js    文件:FileCopier.java   
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) {
    if (exc instanceof FileSystemLoopException) {
        LOGGER.error("File system loop/cycle detected: " + file, exc);
    } else {
        LOGGER.error("Error while copying resource: " + file, exc);
    }
    return CONTINUE;
}
项目:jfrog-idea-plugin    文件:NpmPackageFileFinder.java   
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
    String fileName = file.getFileName().toString();
    if (isYarn(fileName)) {
        throw new IOException("Yarn is not supported");
    }
    if (isPackageFile(fileName)) {
        applicationPaths.add(file.getParent().toString());
    }
    return FileVisitResult.CONTINUE;
}
项目:bazel-buildfarm    文件:Worker.java   
public static void removeDirectory(Path directory) throws IOException {
  Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
    @Override
    public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
      Files.delete(file);
      return FileVisitResult.CONTINUE;
    }

    @Override
    public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
      Files.delete(dir);
      return FileVisitResult.CONTINUE;
    }
  });
}
项目:n4js    文件:FileSystem.java   
@Override
public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) throws IOException {
    if (sourcePath == null) {
        sourcePath = dir;
    } else {
        Files.createDirectories(targetPath.resolve(sourcePath.relativize(dir)));
    }
    return FileVisitResult.CONTINUE;
}
项目:pgcodekeeper    文件:PartialExportTestFileVisitor.java   
@Override
public FileVisitResult visitFile(Path file1, BasicFileAttributes attrs) throws IOException{
    String relativeFilePath = pathToBeCompared.relativize(file1).toString();
    File file2 = new File(pathToCompareTo.toFile(), relativeFilePath);

    if (!file2.exists() && isInSource){
        if (!deletedFiles.contains(relativeFilePath)){
            fail(isInSource() + "file is missing but not in deleted list: " + relativeFilePath);
        }
        deletedFiles.remove(relativeFilePath);
    }
    if (!file2.exists() && !isInSource){
        if (!newFiles.contains(relativeFilePath)){
            fail(isInSource() + "file is missing but not in new list: " + relativeFilePath);
        }
        newFiles.remove(relativeFilePath);
    }
    if (file2.exists() && file2.isDirectory()){
        fail(isInSource() + "file is a directory: " + relativeFilePath);
    }

    if (file2.exists() && !Arrays.equals(Files.readAllBytes(file1), Files.readAllBytes(file2.toPath()))){
        if (!modifiedFiles.containsKey(relativeFilePath)){
            fail(isInSource() + "Source and target files differ, but this file is "
                    + "not in list of modified objects: " + relativeFilePath);
        }
        String hash = modifiedFiles.remove(relativeFilePath);
        File file = isInSource ? file2 : file1.toFile();
        String partialFile = new String(Files.readAllBytes(file.toPath()), PartialExporterTest.UTF_8);

        Assert.assertEquals("Files differ, and partial file has unexpected hash"
                + "\nPartial file:\n" + partialFile,
                hash,
                PgDiffUtils.md5(partialFile));
    }
    return FileVisitResult.CONTINUE;
}
项目:openjdk-jdk10    文件:Basic.java   
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc)
    throws IOException
{
    if (exc != null)
        super.postVisitDirectory(dir, exc);
    if (dir.getFileName() != null)
        indent--;
    return FileVisitResult.CONTINUE;
}
项目:qpp-conversion-tool    文件:CopyFileVisitor.java   
@Override
public FileVisitResult preVisitDirectory(Path directory, BasicFileAttributes attrs) throws IOException {
    if (source == null) {
        source = directory;
    }
    Files.createDirectories(toDestinationPath(directory));
    return FileVisitResult.CONTINUE;
}
项目:tabularius    文件:NumbersFileWalker.java   
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) throws IOException {
    final String path = minimizePath(file);
    Matcher m = Pattern.compile("/(.+)/(\\d)/number-(\\d+)\\..+").matcher(path);
    if (m.find()) {
        String contributor = m.group(1);
        short digit = Short.valueOf(m.group(2));
        short no = Short.valueOf(m.group(3));
        add(contributor, digit, no, path);
    }
    return FileVisitResult.CONTINUE;
}
项目:athena    文件:Tools.java   
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attributes)
        throws IOException {
    if (attributes.isRegularFile()) {
        delete(file);
    }
    return FileVisitResult.CONTINUE;
}
项目:Equella    文件:FileUtils.java   
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException
{
    //Tries again, visitFile can fail trying to get file attributes
    doDelete(file);
    return FileVisitResult.CONTINUE;
}
项目:ViralFileCrypt    文件:ViralFileCrypt.java   
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes mainAtts) {
    File file = path.toFile();
    String fileName = file.getName();
    if (file.isFile()) {
        if (allFiles || (exact != null && exact.equals(fileName))
                || (exact == null && name == null && ext == null && fileName.contains("."))
                || (exact == null && name != null && ext == null && fileName.startsWith(name + "."))
                || (exact == null && name == null && ext != null && fileName.endsWith("." + ext))) {
            paths.add(file.getAbsolutePath());
        }
    }
    return FileVisitResult.CONTINUE;
}
项目:skript-mirror    文件:LibraryLoader.java   
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
  if (MATCHER.matches(file)) {
    Skript.info("Loaded external library " + file.getFileName());
    urls.add(file.toUri().toURL());
  }
  return super.visitFile(file, attrs);
}
项目:marathonv5    文件:Copy.java   
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
    if (copyFile(file, target.resolve(source.relativize(file)))) {
        if (operation == Operation.CUT) {
            try {
                Files.delete(file);
            } catch (IOException e) {
                System.err.format("Unable to create: %s: %s%n", file, e);
            }
        }
    }
    return CONTINUE;
}
项目:GravSupport    文件:CopyFileVisitor.java   
@Override
public FileVisitResult preVisitDirectory(final Path dir,
                                         final BasicFileAttributes attrs) throws IOException {
    if (sourcePath == null) {
        sourcePath = dir;
    } else {
    Files.createDirectories(targetPath.resolve(sourcePath
                .relativize(dir)));
    }
    return FileVisitResult.CONTINUE;
}
项目:SpaceGame    文件:LevelEventRegistry.java   
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
    if (!Files.isHidden(file) && Files.exists(file, LinkOption.NOFOLLOW_LINKS)) {
        try {
            String name = file.toString()
                    .substring(0, file.toString().lastIndexOf('.'))
                    .replaceFirst("/images/", "");
            byte[] bytes = Files.readAllBytes(file);
            packer.pack(name, new Pixmap(bytes, 0, bytes.length));
        } catch (GdxRuntimeException e) {
            System.err.println("Failed to load file: " + file + " as an image.");
        }
    }
    return FileVisitResult.CONTINUE;
}
项目:cdp4j    文件:ChromiumDownloader.java   
@Override
public FileVisitResult visitFile(Path sourceFile, BasicFileAttributes attrs) throws IOException {
    String sourcePath = sourceFile.subpath(1, sourceFile.getNameCount()).toString();
    Path destinationFile = destinationRoot.resolve(sourcePath);
    if (exists(destinationFile)) {
        delete(destinationFile);
    }
    copy(sourceFile, destinationFile);
    return CONTINUE;
}
项目:elasticsearch_my    文件:LogConfigurator.java   
private static void configure(final Settings settings, final Path configsPath, final Path logsPath) throws IOException, UserException {
    Objects.requireNonNull(settings);
    Objects.requireNonNull(configsPath);
    Objects.requireNonNull(logsPath);

    setLogConfigurationSystemProperty(logsPath, settings);
    // we initialize the status logger immediately otherwise Log4j will complain when we try to get the context
    configureStatusLogger();

    final LoggerContext context = (LoggerContext) LogManager.getContext(false);

    final List<AbstractConfiguration> configurations = new ArrayList<>();
    final PropertiesConfigurationFactory factory = new PropertiesConfigurationFactory();
    final Set<FileVisitOption> options = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
    Files.walkFileTree(configsPath, options, Integer.MAX_VALUE, new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
            if (file.getFileName().toString().equals("log4j2.properties")) {
                configurations.add((PropertiesConfiguration) factory.getConfiguration(context, file.toString(), file.toUri()));
            }
            return FileVisitResult.CONTINUE;
        }
    });

    if (configurations.isEmpty()) {
        throw new UserException(
                ExitCodes.CONFIG,
                "no log4j2.properties found; tried [" + configsPath + "] and its subdirectories");
    }

    context.start(new CompositeConfiguration(configurations));

    configureLoggerLevels(settings);
}
项目:GravSupport    文件:CopyFileVisitor.java   
@Override
public FileVisitResult visitFile(final Path file,
final BasicFileAttributes attrs) throws IOException {
Files.copy(file,
    targetPath.resolve(sourcePath.relativize(file)));
return FileVisitResult.CONTINUE;
}
项目:centraldogma    文件:DeletingFileVisitor.java   
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
    delete(dir);

    if (e == null) {
        return FileVisitResult.CONTINUE;
    } else {
        throw e;
    }
}