List of usage examples for java.nio.file FileVisitResult CONTINUE
FileVisitResult CONTINUE
To view the source code for java.nio.file FileVisitResult CONTINUE.
Click Source Link
From source file:DeleteDirectory.java
@Override public FileVisitResult postVisitDirectory(Path directory, IOException exception) throws IOException { if (exception == null) { System.out.println("Deleting " + directory.getFileName()); Files.delete(directory);// w w w . ja va 2s.co m return FileVisitResult.CONTINUE; } else { throw exception; } }
From source file:com.excelsiorjet.api.util.Utils.java
public static void cleanDirectory(File f) throws IOException { Files.walkFileTree(f.toPath(), new FileVisitor<Path>() { @Override/*from w w w .j a va2s . c om*/ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { return FileVisitResult.CONTINUE; } private void deleteFile(File f) throws IOException { if (!f.delete()) { if (f.exists()) { throw new IOException(Txt.s("JetApi.UnableToDelete.Error", f.getAbsolutePath())); } } } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { deleteFile(file.toFile()); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { if (file.toFile().exists()) { throw new IOException(Txt.s("JetApi.UnableToDelete.Error", f.getAbsolutePath())); } return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { deleteFile(dir.toFile()); return FileVisitResult.CONTINUE; } }); }
From source file:Search.java
@Override public FileVisitResult postVisitDirectory(Object dir, IOException exc) throws IOException { System.out.println("Visited: " + (Path) dir); return FileVisitResult.CONTINUE; }
From source file:ListFiles.java
@Override public FileVisitResult postVisitDirectory(Path directory, IOException e) throws IOException { indentionLevel -= indentionAmount;/*from w w w . j av a 2 s .c o m*/ indent(); System.out.println("Finished with the directory: " + directory.getFileName()); return FileVisitResult.CONTINUE; }
From source file:Search.java
@Override public FileVisitResult preVisitDirectory(Object dir, BasicFileAttributes attrs) throws IOException { return FileVisitResult.CONTINUE; }
From source file:Test.java
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) throws IOException { System.out.println("Copying " + source.relativize(file)); Files.copy(file, target.resolve(source.relativize(file))); return FileVisitResult.CONTINUE; }
From source file:org.apdplat.superword.tools.JavaCodeAnalyzer.java
public static Map<String, AtomicInteger> parseDir(String dir) { LOGGER.info("?" + dir); Map<String, AtomicInteger> data = new HashMap<>(); try {/*from w w w . j a v a2 s . com*/ Files.walkFileTree(Paths.get(dir), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Map<String, AtomicInteger> r = parseFile(file.toFile().getAbsolutePath()); r.keySet().forEach(k -> { data.putIfAbsent(k, new AtomicInteger()); data.get(k).addAndGet(r.get(k).get()); }); r.clear(); return FileVisitResult.CONTINUE; } }); } catch (IOException e) { LOGGER.error("?", e); } return data; }
From source file:ListFiles.java
@Override public FileVisitResult preVisitDirectory(Path directory, BasicFileAttributes attributes) throws IOException { indent();/*from ww w. ja v a2 s. c om*/ System.out.println("About to traverse the directory: " + directory.getFileName()); indentionLevel += indentionAmount; return FileVisitResult.CONTINUE; }
From source file:file.FileOperatorTest.java
public static List<Path> testWalkFile() throws Exception { List<Path> paths = Lists.newArrayList(); long a = System.currentTimeMillis(); Files.walkFileTree(Paths.get(ROOT_DIR), new FileVisitor<Path>() { @Override/* w w w. j a v a 2s. c o m*/ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { paths.add(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }); long b = System.currentTimeMillis(); System.out.println(":" + (b - a)); return paths; }
From source file:net.sourceforge.pmd.docs.GenerateRuleDocsCmd.java
public static List<String> findAdditionalRulesets(Path basePath) { try {//from ww w . ja va 2 s . co m List<String> additionalRulesets = new ArrayList<>(); Pattern rulesetPattern = Pattern.compile("^.+" + Pattern.quote(File.separator) + "pmd-\\w+" + Pattern.quote(FilenameUtils.normalize("/src/main/resources/rulesets/")) + "\\w+" + Pattern.quote(File.separator) + "\\w+.xml$"); Files.walkFileTree(basePath, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (rulesetPattern.matcher(file.toString()).matches()) { additionalRulesets.add(file.toString()); } return FileVisitResult.CONTINUE; } }); return additionalRulesets; } catch (IOException e) { throw new RuntimeException(e); } }