Questions tagged [simplefilevisitor]

SimpleFileVisitor is a class with default implementation to visit all files and on error it will re-throw errors. Instead of implementing FileVisitor we can choose to extend SimpleFileVisitor and override only methods of our need.

SimpleFileVisitor is a class with default implementation to visit all files and on error it will re-throw errors. Instead of implementing FileVisitor we can choose to extend SimpleFileVisitor and override only methods of our need.

10 questions
1
vote
1 answer

SimpleFileVisitor to walk a directory tree to find all .txt files except in two sub directories

I want to traverse a directory tree with many sub directories. My target is to print all .txt file except those which are inside subdir and anotherdir sub-directories. I am able to achieve this with the below code. public static void main(String[]…
0
votes
0 answers

Write the results of Files.walkFileTree () operation to the file in "Tree" format (Java)

My task is to insert the directory path to the command line and write the results of Files.walkFileTree () operation to the file in "Tree" format. I have the following code: public class IOTask { public static void main(String[] args) { File…
Shubt
  • 17
  • 6
0
votes
1 answer

Convert Files.walk to a SimplefileVisitor

Say that i have a thing like this Stream files = Files.walk(Paths.get(somePath)) That i then stream through and collect but then i want to convert it to use a SimpleFileVisitor instead because it is needed, how would i do? i have googled and…
novafluff
  • 891
  • 1
  • 12
  • 30
0
votes
0 answers

FileVisitor using Path class - how to 'return' the directory structure?

I am writing a directory listing code for a client-server system using java Path class. I created a custom class for that which works fine. However, I want to display the results on Client rather than Server, which I am not able to figure out how. I…
NJWeb
  • 35
  • 1
  • 8
0
votes
1 answer

Java SimpleFileVisitor Issue when encountering permission errors

I am trying to search my hard drive for mp4 files and copy them into a specific folder. The problem is that I don't have permission to access folders like: "C:\Documents and Settings", so my program stops when it encounters those rather than…
Vincent
  • 23
  • 5
0
votes
1 answer

Continue a visit of SimpleFileVisitor

I'm not sure if I'm using the right approach so I'm open to new ideas before telling me that i'm doing it wrong. I have an array of directories path that I need to look for files. Let's say all .txt at example. Now I run a Files.walkFileTree(...)…
Umuril Lyerood
  • 175
  • 1
  • 1
  • 9
0
votes
1 answer

How to delete all files, based on a specific character in filenames, using Java

I am wondering if there is a way to enhance the code below and not only match but also delete all files and directories that contain the "e" character in their name. Any help is appreciated! Thank you in advance. Here is the code: import…
0
votes
0 answers

Simple File Visitor in Java

I'm using the simple file visitor for the first time and the documentation seems to be a little less than friendly. Basically I want to visit the directory tree and log the number of folders, the number of total files, and the number of different…
Zeus
  • 2,213
  • 8
  • 28
  • 45
0
votes
0 answers

Java on Macintosh directoryStream shows Applications as Folders

I feel like I must be missing something. It seems like this should be really easy but I can't seem to find an answer to this question. I'm writing code in Java 8 using both Files.newDirectoryStream() class SimpleFileVisitor() {} On a Macintosh…
0
votes
1 answer

Moving not empty directory recursively using Java NIO.2 FileVisitor and Files.walkFileTree(...)

I saw a lot of examples of how to copy or delete files recursively by using Java NIO.2. For example, this is how to copy a folder with all its contents: /** * Copies a folder with all contents recursively. Class implements * {@code FileVisitor}…
Ernestas Gruodis
  • 8,567
  • 14
  • 55
  • 117