List of usage examples for java.nio.file Files isHidden
public static boolean isHidden(Path path) throws IOException
From source file:Main.java
public static void main(String[] args) { DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() { public boolean accept(Path file) throws IOException { return (Files.isHidden(file)); }/*from ww w. ja v a2 s .c o m*/ }; Path directory = Paths.get("C:/Windows"); try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(directory, filter)) { for (Path file : directoryStream) { System.out.println(file.getFileName()); } } catch (IOException | DirectoryIteratorException ex) { ex.printStackTrace(); } }
From source file:Test.java
public static void main(String[] args) throws Exception { Path path = FileSystems.getDefault().getPath("./file2.log"); System.out.println("File Size:" + Files.size(path)); System.out.println("Is Directory:" + Files.isDirectory(path)); System.out.println("Is Regular File:" + Files.isRegularFile(path)); System.out.println("Is Symbolic Link:" + Files.isSymbolicLink(path)); System.out.println("Is Hidden:" + Files.isHidden(path)); System.out.println("Last Modified Time:" + Files.getLastModifiedTime(path)); System.out.println("Owner:" + Files.getOwner(path)); DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class); System.out.println("Archive :" + view.readAttributes().isArchive()); System.out.println("Hidden :" + view.readAttributes().isHidden()); System.out.println("Read-only:" + view.readAttributes().isReadOnly()); System.out.println("System :" + view.readAttributes().isSystem()); view.setHidden(false);/*from w w w .j av a 2 s . c om*/ }
From source file:Test.java
private static void displayFileAttributes(Path path) throws Exception { String format = "Exists: %s %n" + "notExists: %s %n" + "Directory: %s %n" + "Regular: %s %n" + "Executable: %s %n" + "Readable: %s %n" + "Writable: %s %n" + "Hidden: %s %n" + "Symbolic: %s %n" + "Last Modified Date: %s %n" + "Size: %s %n"; System.out.printf(format, Files.exists(path, LinkOption.NOFOLLOW_LINKS), Files.notExists(path, LinkOption.NOFOLLOW_LINKS), Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS), Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS), Files.isExecutable(path), Files.isReadable(path), Files.isWritable(path), Files.isHidden(path), Files.isSymbolicLink(path), Files.getLastModifiedTime(path, LinkOption.NOFOLLOW_LINKS), Files.size(path)); }
From source file:com.liferay.sync.engine.util.FileUtil.java
public static boolean isIgnoredFilePath(Path filePath) throws Exception { String fileName = String.valueOf(filePath.getFileName()); if (_syncFileIgnoreNames.contains(fileName) || (PropsValues.SYNC_FILE_IGNORE_HIDDEN && Files.isHidden(filePath)) || Files.isSymbolicLink(filePath) || fileName.endsWith(".lnk")) { return true; }/* w w w . j a v a2 s. c o m*/ return false; }
From source file:client.tools.ClientRecovery.java
/** * Starts the recovery process./* w w w .ja va2s .c om*/ * * @return <code>true</code>, if this recovery was successfully executed. * Otherwise, <code>false</code>. */ public boolean execute() { try { if (Files.isHidden(syncPath) || !syncPath.startsWith(filesPath)) { Files.walkFileTree(syncPath, new DeleteTempFileVisitor(syncPath)); } Files.walkFileTree(filesPath, new DeleteTempFileVisitor(syncPath)); return true; } catch (IOException e) { e.printStackTrace(); return false; } }
From source file:io.github.swagger2markup.Swagger2MarkupConverter.java
/** * Creates a Swagger2MarkupConverter.Builder using a local Path. * * @param swaggerPath the local Path//from w w w . j a v a 2 s . c om * @return a Swagger2MarkupConverter */ public static Builder from(Path swaggerPath) { Validate.notNull(swaggerPath, "swaggerPath must not be null"); if (Files.notExists(swaggerPath)) { throw new IllegalArgumentException(String.format("swaggerPath does not exist: %s", swaggerPath)); } try { if (Files.isHidden(swaggerPath)) { throw new IllegalArgumentException("swaggerPath must not be a hidden file"); } } catch (IOException e) { throw new RuntimeException("Failed to check if swaggerPath is a hidden file", e); } return new Builder(swaggerPath); }
From source file:org.ballerinalang.composer.service.workspace.local.LocalFSWorkspace.java
@Override public JsonArray listDirectoriesInPath(String path) throws IOException { Path ioPath = Paths.get(path); JsonArray dirs = new JsonArray(); Iterator<Path> iterator = Files.list(ioPath).iterator(); while (iterator.hasNext()) { Path next = iterator.next(); if (Files.isDirectory(next) && !Files.isHidden(next)) { JsonObject jsnObj = getJsonObjForFile(next, true); dirs.add(jsnObj);/* ww w . ja v a2 s.c om*/ } } return dirs; }
From source file:at.ac.tuwien.infosys.repository.LocalComponentRepository.java
protected List<Path> list(Path path) { List<Path> results = new ArrayList<Path>(); DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() { @Override/*from ww w . j a v a2 s.com*/ public boolean accept(Path entry) throws IOException { return (!Files.isHidden(entry) && Files.isRegularFile(entry)); } }; try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(path, filter)) { for (Path p : directoryStream) { results.add(p); } } catch (IOException ex) { ex.printStackTrace(); } return results; }
From source file:spdxedit.SpdxLogic.java
/** * Creates a new package with the specified license, name, comment, and root * path.//ww w .j a va 2 s . co m * * @param pkgRootPath * The path from which the files will be included into the * package. If absent, creates a "remote" package, i.e. one * without files, just referencing a remote dependency. * @param name * @param omitHiddenFiles * @param declaredLicense * @param downloadLocation * @return */ public static SpdxPackage createSpdxPackageForPath(Optional<Path> pkgRootPath, AnyLicenseInfo declaredLicense, String name, String downloadLocation, final boolean omitHiddenFiles) { Objects.requireNonNull(pkgRootPath); try { SpdxPackage pkg = new SpdxPackage(name, declaredLicense, new AnyLicenseInfo[] {} /* Licences from files */, null /* Declared licenses */, declaredLicense, downloadLocation, new SpdxFile[] {} /* Files */, new SpdxPackageVerificationCode(null, new String[] {})); pkg.setLicenseInfosFromFiles(new AnyLicenseInfo[] { new SpdxNoAssertionLicense() }); pkg.setCopyrightText("NOASSERTION"); if (pkgRootPath.isPresent()) { // Add files in path List<SpdxFile> addedFiles = new LinkedList<>(); String baseUri = pkgRootPath.get().toUri().toString(); FileVisitor<Path> fileVisitor = new FileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (omitHiddenFiles && dir.getFileName().toString().startsWith(".")) { return FileVisitResult.SKIP_SUBTREE; } else return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { // Skip if omitHidden is set and this file is hidden. if (omitHiddenFiles && (file.getFileName().toString().startsWith(".") || Files.isHidden(file))) return FileVisitResult.CONTINUE; try { SpdxFile addedFile = newSpdxFile(file, baseUri); addedFiles.add(addedFile); } catch (InvalidSPDXAnalysisException e) { throw new RuntimeException(e); } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { logger.error("Unable to add file ", file.toAbsolutePath().toString()); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }; Files.walkFileTree(pkgRootPath.get(), fileVisitor); SpdxFile[] files = addedFiles.stream().toArray(size -> new SpdxFile[size]); pkg.setFiles(files); recomputeVerificationCode(pkg); } else { //External package pkg.setFilesAnalyzed(false); pkg.setPackageVerificationCode(null); } return pkg; } catch (InvalidSPDXAnalysisException | IOException e) { throw new RuntimeException(e); } }
From source file:org.ballerinalang.composer.service.fs.LocalFileSystem.java
/** * {@inheritDoc}/*from w w w . j av a 2 s . c o m*/ */ @Override public JsonArray listFilesInPath(String path, List<String> extensions) throws IOException { Path ioPath = Paths.get(path); JsonArray dirs = new JsonArray(); Iterator<Path> iterator = Files.list(ioPath).sorted().iterator(); while (iterator.hasNext()) { Path next = iterator.next(); if ((Files.isDirectory(next) || Files.isRegularFile(next)) && !Files.isHidden(next) && !isWindowsSystemFile(next)) { JsonObject jsnObj = getJsonObjForFile(next, extensions); if (Files.isRegularFile(next)) { Path fileName = next.getFileName(); SuffixFileFilter fileFilter = new SuffixFileFilter(extensions, INSENSITIVE); if (null != fileName && fileFilter.accept(next.toFile())) { jsnObj.addProperty(FILE_FULL_PATH, next.toString()); jsnObj.addProperty(FILE_NAME, FilenameUtils.getBaseName(next.toString())); jsnObj.addProperty(FILE_PATH, FilenameUtils.getFullPath(next.toString())); jsnObj.addProperty(EXTENSION, FilenameUtils.getExtension(next.toString())); dirs.add(jsnObj); } } else { dirs.add(jsnObj); } } } return dirs; }