List of usage examples for java.nio.file PathMatcher matches
boolean matches(Path path);
From source file:se.trixon.filebydate.Operation.java
private boolean generateFileList() { mListener.onOperationLog(""); mListener.onOperationLog(Dict.GENERATING_FILELIST.toString()); PathMatcher pathMatcher = mProfile.getPathMatcher(); EnumSet<FileVisitOption> fileVisitOptions = EnumSet.noneOf(FileVisitOption.class); if (mProfile.isFollowLinks()) { fileVisitOptions = EnumSet.of(FileVisitOption.FOLLOW_LINKS); }/* w w w . ja va2 s . co m*/ File file = mProfile.getSourceDir(); if (file.isDirectory()) { FileVisitor fileVisitor = new FileVisitor(pathMatcher, mFiles, this); try { if (mProfile.isRecursive()) { Files.walkFileTree(file.toPath(), fileVisitOptions, Integer.MAX_VALUE, fileVisitor); } else { Files.walkFileTree(file.toPath(), fileVisitOptions, 1, fileVisitor); } if (fileVisitor.isInterrupted()) { return false; } } catch (IOException ex) { Xlog.e(getClass(), ex.getLocalizedMessage()); } } else if (file.isFile() && pathMatcher.matches(file.toPath().getFileName())) { mFiles.add(file); } if (mFiles.isEmpty()) { mListener.onOperationLog(Dict.FILELIST_EMPTY.toString()); } else { Collections.sort(mFiles); } return true; }
From source file:se.trixon.mapollage.Operation.java
private boolean generateFileList() throws IOException { mListener.onOperationLog(""); mListener.onOperationLog(Dict.GENERATING_FILELIST.toString()); PathMatcher pathMatcher = mProfileSource.getPathMatcher(); EnumSet<FileVisitOption> fileVisitOptions; if (mProfileSource.isFollowLinks()) { fileVisitOptions = EnumSet.of(FileVisitOption.FOLLOW_LINKS); } else {//from ww w . j a v a 2s.c o m fileVisitOptions = EnumSet.noneOf(FileVisitOption.class); } File file = mProfileSource.getDir(); if (file.isDirectory()) { FileVisitor fileVisitor = new FileVisitor(pathMatcher, mFiles, file, this); try { if (mProfileSource.isRecursive()) { Files.walkFileTree(file.toPath(), fileVisitOptions, Integer.MAX_VALUE, fileVisitor); } else { Files.walkFileTree(file.toPath(), fileVisitOptions, 1, fileVisitor); } if (fileVisitor.isInterrupted()) { return false; } } catch (IOException ex) { throw new IOException(String.format("E000 %s", file.getAbsolutePath())); } } else if (file.isFile() && pathMatcher.matches(file.toPath().getFileName())) { mFiles.add(file); } if (mFiles.isEmpty()) { mListener.onOperationFinished(Dict.FILELIST_EMPTY.toString(), 0); } else { Collections.sort(mFiles); } return true; }